substring()用法

1.substring(int  indx)

  直接返回从角标为indx的字符开始一直到结尾的字符串,"abcde".substring(2) 返回的是 "cde"。

2.substring(int start,int end)

  截取角标在 [start,end) 区间的字符串,注意是左闭右开的。

  ①end大于字符串,运行异常(StringIndexOutOfBoundsException);但是可以等于,因为是左闭右开的空间,右侧值取不到

  ②start>end,运行异常(StringIndexOutOfBoundsException

  ③start<end,一切正常

猜你喜欢

转载自www.cnblogs.com/tiny-me/p/11783916.html
今日推荐