As @afsantos says, the ArrayList
class is inherently limited to Integer.MAX_VALUE
entries because of the limitations of Java arrays.
LinkedList
doesn't have this limitation, but it is (nonetheless) expensive:
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.
Indexing is an O(N)
operation compared with O(1)
for an array-based list.
Here is a link to Java library that supports huge in-memory collections using direct mapped memory and/or encoding of the elements:
There could be other alternatives out there.
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 ...)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…