【问题排查】StringIndexOutOfBoundsException


工作中遇到 java.lang.StringIndexOutOfBoundsException ,查看网上资料,总结如下

 

1、异常定义:

Java API指出StringIndexOutOfBoundsException异常
Thrown by String methods to indicate that an index is either negative or greater than the size of the string. For some methods such as the charAt method。

以 java.lang.StringIndexOutOfBoundsException: String index out of range: 10 异常举例, 当String.length()<10,而你又要取index>=10 的字符时,会抛出上面的异常

 

2、关于String使用

String是不可变类,每一步操作都会返回新的String变量,占用时间和内存空间;

如 : String = String + " b"; 

实际上是新创建了个String变量 

 

 

 

参考资料:

http://blog.chinaunix.net/uid-11361941-id-2880422.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM