How much data can be added in java.util.List in Java at the maximum?
Is there any default size of an ArrayList?
size() method returns the size of the list as integer value. Integer max value is 2^31 and this value is equal to the 2147483647.
The theoretical limit for ArrayList capacity is Integer. MAX_VALUE, a.k.a. 2^31 - 1, a.k.a. 2,147,483,647. But you'll probably get an OutOfMemoryError long before that time because, well, you run out of memory. An ArrayList containing 11 million references should be about 42MB, assuming a reference is 4 bytes long.
Since ArrayList in Java is backed by a built-in array, the limit on the size is equal the same as the limit on the size of an array, i.e. 2147483647. Since your project is for android platform, you would run out of memory before reaching this limit. However, 8000 is a relatively small number.
The capacity property in ArrayList class gets or sets the number of elements that the ArrayList can contain. The default capacity is 4. If 5 elements are there, then its capacity is doubled and would be 8. This goes on.
It depends on the List
implementation. Since you index arrays with int
s, an ArrayList
can't hold more than Integer.MAX_VALUE
elements. A LinkedList
isn't limited in the same way, though, and can contain any amount of elements.
It would depend on the implementation, but the limit is not defined by the List
interface.
The interface however defines the size()
method, which returns an int
.
Returns the number of elements in this list. If this list contains more than
Integer.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.
So, no limit, but after you reach Integer.MAX_VALUE
, the behaviour of the list changes a bit
ArrayList
(which is tagged) is backed by an array, and is limited to the size of the array - i.e. Integer.MAX_VALUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With