string index out of range string index out of range是什么意思


string index out of range string index out of range是什么意思

文章插图
大家好,小甜来为大家解答以下的问题 , 关于string index out of range是什么意思,string index out of range这个很多人还不知道,现在让我们一起来看看吧!
【string index out of range string index out of range是什么意思】1、String index out of range :10字符串的下标越界.当使用的索引 超过字符串自身的长度时. 就会报出该异常比如String s = "举头望明月";char c = s.charAt(5);//得到下标是5的字符字符串长度是5个字, 下标从0开始,也就是最大的下标只有4所以这时系统就会抛出异常Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5需要注意 java中(数组,集合,字符串...等)下标都是从0开始算起的 , 最大下标就是 长度-1 。
本文分享完毕 , 希望对大家有所帮助 。

    推荐阅读