Java - Chaîne lastIndexOf () fromIndex

La description

Cette méthode retourne l'index dans cette chaîne de la dernière occurrence de la sous-chaîne spécifiée, en effectuant une recherche en arrière en commençant à l'index spécifié.

Syntaxe

Voici la syntaxe de cette méthode -

public int lastIndexOf(String str, int fromIndex)

Paramètres

Voici le détail des paramètres -

  • fromIndex - l'index à partir duquel démarrer la recherche.

  • str - une chaîne.

Valeur de retour

  • Cette méthode renvoie l'index.

Exemple

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str = new String("Welcome to Tutorialspoint.com");
      String SubStr1 = new String("Tutorials" );
      System.out.print("Found Last Index :" );
      System.out.println( Str.lastIndexOf( SubStr1, 15 ));
   }
}

Cela produira le résultat suivant -

Production

Found Last Index :11