substring解决了如何在指定位置将一个字符串划分为子串
- 单参数形式:返回从起始位置到结尾之间的子串**(起始索引从0开始)**
public class SubStringReview {public static void main(String[] args) {String s = "Java is great";System.out.println(s);String s2 = s.substring(0);System.out.println(s2);}
}
2.双参数形式:获得从起始索引到结束索引之间的字符串
public class SubStringReview {public static void main(String[] args) {String s = "Java is great";System.out.println(s);String s2 = s.substring(1,3);System.out.println(s2);}
}