Amount of elements in ArrayList

ArrayList can't hold more than Integer.MAX_VALUE elements.

So 2147483647 is the max.


The size of ArrayList is Integer.MAX_VALUE.

/**
  * Returns the number of elements in this list.  If this list contains
  * more than <tt>Integer.MAX_VALUE</tt> elements, returns
  * <tt>Integer.MAX_VALUE</tt>.
  *
  * @return the number of elements in this list
  */
 int size();

It is because ArrayList uses array internally and theoretically an array can be of Integer.MAX_VALUE in size at maximum. For further information, you can see this.


ArrayList which is backed by an array, and is limited to the size of the array - i.e. Integer.MAX_VALUE.

A LinkedList isn't limited in the same way, though, and can contain any amount of elements.

see similar question max. length of List in Java

How many data a list can hold at the maximum to have other aspects on max size of list

Tags:

Java

Arraylist