工作中遇到 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