public String substring(int beginIndex, int endIndex)
beginIndex—起始索引(含)。
endIndex—结束索引,不包含。
例:
public class Test {
public static void main(String args[]) {
String Str = new String("Hello World");
System.out.println(Str.substring(3, 8));
}
}
输出:“ lo Wo”
从3到7的索引。
另外还有另一种substring()方法:
public String substring(int beginIndex)
beginIndex—包含索引的开始索引。返回从beginIndex主字符串开始到结尾的子字符串。
例:
public class Test {
public static void main(String args[]) {
String Str = new String("Hello World");
System.out.println(Str.substring(3));
}
}
输出:“ lo World”
从3到最后一个索引。