package basic;
/**
* create by liuzhiwei on 2020/3/29
*/
public class StringTest {
public static void main(String[] args) {
//线程安全的
StringBuffer stringBuffer = new StringBuffer();
//线程安全的
StringBuilder stringBuilder = new StringBuilder();
String s = new String("0123456789");
System.out.println(s.substring(0, 5)); //[0,5)左包含 右不包含
System.out.println(s.substring(5)); //从索引下标开始
int length = s.length();
System.out.println(s.substring(5, s.length()));
//Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
System.out.println(s.substring(5, 11));
}
}
String substring(a) 和substring(a,b)
最新推荐文章于 2022-09-26 21:46:58 发布