Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many values can an ArrayList hold?

Tags:

java

arraylist

I'm new to Java and I would like to know how many values can a arraylist hold.

I'm building an android project that takes values from a database table (I'm printing the values using json and calling the file in java), and records this values on a arraylist.

If my table has like 8000 records, would it be possible to the arraylist hold all these records?

Thank you.

like image 374
Michael Jackson Avatar asked Oct 29 '25 08:10

Michael Jackson


1 Answers

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. You could still run out of memory if each individual record takes a significant amount of memory, but it is going to happen before you hit the limit on the number of ArrayList entries.

like image 58
Sergey Kalinichenko Avatar answered Oct 31 '25 00:10

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!