转换'诠释'到'长'或访问过长阵列“长” [英] converting 'int' to 'long' or accessing too long array with 'long'
问题描述
比方说,我有一个数组,它是足够长的时间访问任何其指数与 INT
,有没有什么办法与<$访问这些数组的索引C $ C>长?而如何在Java处理这种类型的数组?例如:
Let's say I have an array that is long enough to access any of its index with int
, is there any way to access the index of such an array with long
? And how the Java handle this kind of array? Example:
int[] a = new int[]{1,5,2,4........9,2,1}
假设上面的数组中的 9,2,1
正处在一个超出 INT
的索引范围(2 31 )。
我将如何访问这些内容?
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?
推荐答案
您不会 - 数组索引总是在Java的 INT
值。它不允许有更多的数组比 Integer.MAX_VALUE的
元素。
You wouldn't - array indexes are always int
values in Java. It doesn't allow for an array with more than Integer.MAX_VALUE
elements.
数组的长度再由长度
字段,它的类型是psented $ P $ INT
。因此,它是不可能有一个长度大于 Integer.MAX_VALUE的
创建更大的数组。
The length of an array is represented by the length
field, which is of type int
. Therefore it is impossible to create an array with a length greater than Integer.MAX_VALUE
.
借助规范不显式调用了这一点,但你可以从所涉及的类型推断吧。
The spec doesn't explicitly call this out, but you can infer it from the types involved.
这篇关于转换'诠释'到'长'或访问过长阵列“长”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!