Is there a longer than int Java List?

后端 未结 3 869
谎友^
谎友^ 2020-12-19 16:47

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?

3条回答
  •  盖世英雄少女心
    2020-12-19 17:33

    From the List documentation:

    int size()

    Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

    So, even if a specific implementation of List holds Long.MAX_VALUE elements, you wouldn't know, using the standard List interface.

    I'm not sure if one exists, but my bet would be on LinkedList, since ArrayList is based on arrays, and those can't hold more than Integer.MAX_VALUE elements.

提交回复
热议问题