String str="x";
System.out.println(str.substring(1));
来自 Javadoc:
String java.lang.String.substring(int beginIndex)
:返回一个新字符串,该字符串是该字符串的子字符串。这子字符串以指定索引处的字符开头并延伸到该字符串的末尾。
看看JavaDoc,并特别注意“空”的例子:
Returns a string that is a substring of this string. The substring begins
with the character at the specified index and extends to the end of
this string.
Examples:
"unhappy".substring(2) returns "happy"
"Harbison".substring(3) returns "bison"
"emptiness".substring(9) returns "" (an empty string)
Parameters:
beginIndex the beginning index, inclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if beginIndex is negative or larger than
the length of this String object
抛出异常if beginIndex is negative or larger than the length of this String object
;在您的情况下,beginIndex 等于字符串的长度,并且不大于。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)