【問題排查】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