假设我有一个足够长的数组,可以使用以下命令访问其任何索引int
,有没有办法访问这样一个数组的索引long
?那么Java是如何处理这种数组的呢?例子:
int[] a = new int[]{1,5,2,4........9,2,1}
Assume in the above array that 9,2,1
are at indices that are beyond the range of int
(231).
How would I access these elements?
你不会 - 数组索引总是int
Java 中的值。它不允许数组超过Integer.MAX_VALUE
元素。
数组的长度表示为length
字段,其类型为int
。因此不可能创建长度大于Integer.MAX_VALUE
.
The spec http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html没有明确指出这一点,但您可以从涉及的类型中推断出来。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)