Méthode substring() de Java
La méthode substring() renvoie une sous-chaîne de la chaîne.
Syntaxe
public String substring(int beginIndex) ou public String substring(int beginIndex, int endIndex)
Parameters
beginIndex-- index de début (inclus), l'index commence à 0.
endIndex-- index de fin (exclu).

Valeur de retour
La sous-chaîne.
Exemple
public class ExampleTest {
public static void main(String args[]) {
String Str = new String("This is text");
System.out.print("Valeur de retour :" );
System.out.println(Str.substring(4) );
System.out.print("Valeur de retour :" );
System.out.println(Str.substring(4, 10) );
}
}
Le résultat de l'exécution du programme ci-dessus est :
返回值 : is text 返回值 : is te
Autres extensions
Classe String de Java