【問題排查】StringIndexOutOfBoundsException

工做中遇到 java.lang.StringIndexOutOfBoundsException ,查看網上資料,總結以下html

 

一、異常定義:java

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 的字符時,會拋出上面的異常ui

 

二、關於String使用spa

String是不可變類,每一步操做都會返回新的String變量,佔用時間和內存空間;.net

如 : String = String + " b"; unix

其實是新建立了個String變量 code

 

 

 

參考資料:htm

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

相關文章
相關標籤/搜索