ArrayIndexOutOfBoundsException和IndexOutOfBoundsException之间的区别? [英] Difference between ArrayIndexOutOfBoundsException and IndexOutOfBoundsException?

查看:362
本文介绍了ArrayIndexOutOfBoundsException和IndexOutOfBoundsException之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么情况下应使用 ArrayIndexOutOfBoundsException 和`IndexOutOfBoundsException?

What are the use cases in which we should use ArrayIndexOutOfBoundsException and `IndexOutOfBoundsException one over another?

推荐答案

IndexOutOfBoundsException :抛出该异常表示某种索引(例如数组,字符串或向量)超出了范围。

IndexOutOfBoundsException :Thrown to indicate that an index of some sort (such as to an array, to a string, or to a vector) is out of range.

ArrayIndexOutOfBoundsException StringIndexOutOfBoundsException
是两个类,它们实现了 IndexOutOfBoundsException

ArrayIndexOutOfBoundsException :抛出该异常表示已使用非法索引访问了数组。索引为负或大于或等于数组的大小。

ArrayIndexOutOfBoundsException: Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.

StringIndexOutOfBoundsException :由String方法抛出,以指示索引为负数或大于字符串的大小。对于某些方法,例如charAt方法,当索引等于字符串的大小时也会抛出此异常。

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, this exception also is thrown when the index is equal to the size of the string.

这篇关于ArrayIndexOutOfBoundsException和IndexOutOfBoundsException之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆