Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1960)
at xyz.hashdog.test.Test.main(Test.java:19)
字符串下标越界
在截取字符串的时候,需要用到变量去做加减运算,一定要保证不为负数
public static void main(String[] args) {
String s = "ssss";
int a = 2;
s.substring(a-3,2);
}
还没有评论,来说两句吧...