Number of Elements in ArrayList

I am creating a chat application. Current I have all the posts in ArrayList that make me think: how many elements are in the ArrayList design? 100? 1,000? 10,000?

+6
source share
4 answers

ArrayList cannot contain more Integer.MAX_VALUE elements.

Thus, 2147483647 is the maximum.

+11
source

The size of the 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(); 

This is because an ArrayList uses an array for internal use, and theoretically an array can have Integer.MAX_VALUE size of Integer.MAX_VALUE . For more information, you can see this .

+10
source

An ArrayList that is supported by the array and is limited by the size of the array - that is, Integer.MAX_VALUE.

LinkedList is not limited to the same method and can contain any number of elements.

see similar question max. list length in java

How much data the list can contain maximum; have other aspects with the maximum size of the list

+6
source

An ArrayList can contain any number of elements up to Integer.MAX_VALUE - this is due to a constructive decision to use the int data type for indexes. However, the important thing is how you allocate memory for it - memory allocation is slow - and how you process / access the elements. However, from one aspect of storage you are limited to MAX_VALUE . In Java, this is 2 ^ 31-1 = 2,147,483,647.

For any normal use, this should be enough. However, if you need more, you can easily get the source code for it and modify it to use long as the index data type, and then be limited to Long.MAX_VALUE .

+3
source

Source: https://habr.com/ru/post/948633/


All Articles