javaarraylistlong-integermaxlength

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?


Solution

  • 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:

    Here is a link to Java library that supports huge in-memory collections using direct mapped memory and/or encoding of the elements:

    And here is a link to a huge collections library with an ArrayList analog that uses 2-level arrays (arrays of arrays) to avoid the 32 bit address limit.

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