Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

arraylist - Is there a longer than int Java List?

I can't seem to find a Java List that's max length is long's max value.

Does such a List exist?

If so, where?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ...)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...