首页 >> 问答 >

string index out of range -1(string index out of range)

2022-09-25 01:33:28 来源: 用户: 

您好,今天帅帅来为大家解答以上的问题。string index out of range -1,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。

本文就为大家分享到这里,希望小伙伴们会喜欢。

  免责声明:本文由用户上传,与本网站立场无关。财经信息仅供读者参考,并不构成投资建议。投资者据此操作,风险自担。 如有侵权请联系删除!

 
分享:
最新文章