0

According to these questions from SO:

  1. list max size
  2. array max length

The max length of an array is Integer.MAX_VALUE - 5,
whereas the max size of a List is Integer.MAX_VALUE

When you look at an ArrayList, it is just a wrapper around an array.

How can the wrapper allow a length longer than that of the array under the hood?

Community
  • 1
  • 1
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • 2
    The answer you are quoting about the list is probably wrong. – Radiodef Apr 06 '14 at 11:27
  • 1
    A "List" has no maximum size. List is just an interface, and the max size will depend on its implementation: Array List can not contain more elements than an array itself. If you need more elements in a list, use a LinkedList, which is just limited by your system memory. – dognose Apr 06 '14 at 11:33
  • In question on which I refers another information – gstackoverflow Apr 06 '14 at 15:03
  • @Radiodef this answer is enough voted... – gstackoverflow Apr 06 '14 at 15:56
  • @Radiodef **List java doc**: int size() Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE. Conclusion - if List contain more than Integer.MAX_VALUE values - we cannot to know it. – gstackoverflow Apr 07 '14 at 17:50

0 Answers0