?substring()作用:用于切割字符串,索引从0开始
两个参数,(beginIndex,endIndex)
public class SubstringDemo {
public static void main(String[] args) {
String str = "abcdefghijklmn";
/**(beginIndex,endIndex) 从当前开始索引(3)切割,不包括结束索引*/
String substring = str.substring(3, 6);
/** 输出:def */
System.out.println(substring);
}
}
一个参数,(beginIndex)
public class SubstringDemo {
public static void main(String[] args) {
String str = "abcdefghijklmn";
/**(beginIndex)*/
String substring1 = str.substring(4);
/** 输出:efghijklmn */
System.out.println(substring1);
}
}