有比 int Java List 更长的吗? [英] Is there a longer than int Java List?
问题描述
我似乎找不到最大长度是 long
的最大值的 Java List
.
I can't seem to find a Java List
that's max length is long
's max value.
这样的List
存在吗?
如果有,在哪里?
推荐答案
正如@afsantos 所说,ArrayList
类本质上仅限于 Integer.MAX_VALUE
条目,因为Java 数组的局限性.
As @afsantos says, the ArrayList
class is inherently limited to Integer.MAX_VALUE
entries because of the limitations of Java arrays.
LinkedList
没有这个限制,但它(尽管如此)很昂贵:
LinkedList
doesn't have this limitation, but it is (nonetheless) expensive:
与基于数组的表示仅一个引用相比,每个条目都会产生 2 个引用加上对象头大小的内存开销.
Each entry incurs an memory overhead of 2 references plus the size of an object header ... compared to just one reference for an array-based representation.
与基于数组的列表的O(1)
相比,索引是一个O(N)
操作.
Indexing is an O(N)
operation compared with O(1)
for an array-based list.
这里是 Java 库的链接,该库支持使用直接映射内存和/或元素编码的巨大内存中集合:
Here is a link to Java library that supports huge in-memory collections using direct mapped memory and/or encoding of the elements:
可能还有其他选择.
人们还可以设想使用数组数组而不是单个数组的常规数组列表的大"变体.但是如果你允许插入到列表的中间,实现 O(1)
查找变得困难/昂贵.(这可能就是我找不到 Google 示例的原因...)
One could also envisage a "big" variant of regular array lists that used an array of arrays rather than a single array. But if you allow insertion into the middle of the list, it becomes difficult / expensive to achieve O(1)
lookup. (That might be why I couldn't find an example with Google ...)
这篇关于有比 int Java List 更长的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!