Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much data can a List can hold at the maximum?

How much data can be added in java.util.List in Java at the maximum?

Is there any default size of an ArrayList?

like image 371
Paul Avatar asked Sep 22 '10 09:09

Paul


People also ask

How much data can a list store?

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.

How much data can list hold in Java?

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.

How many objects can an ArrayList hold?

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.

What is the capacity of ArrayList in Java?

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.


2 Answers

It depends on the List implementation. Since you index arrays with ints, 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.

like image 187
gustafc Avatar answered Oct 12 '22 23:10

gustafc


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, returns Integer.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

like image 41
Bozho Avatar answered Oct 12 '22 23:10

Bozho