public String substring(int beginIndex, int endIndex)
beginIndex- Der Anfangsindex einschließlich.
endIndex- der Endindex, exklusiv.
Beispiel:
public class Test {
public static void main(String args[]) {
String Str = new String("Hello World");
System.out.println(Str.substring(3, 8));
}
}
Ausgabe: "lo Wo"
Von 3 bis 7 Index.
Es gibt auch eine andere Art von substring()Methode:
public String substring(int beginIndex)
beginIndex- Der Anfangsindex einschließlich. Gibt eine Unterzeichenfolge zurück beginIndex, die bis zum Ende der Hauptzeichenfolge beginnt .
Beispiel:
public class Test {
public static void main(String args[]) {
String Str = new String("Hello World");
System.out.println(Str.substring(3));
}
}
Ausgabe: "lo World"
Von 3 bis zum letzten Index.