Is creating an array and creating an arraylist the same thing in Java? I hear many different stories with regard to this so if you could point me into the right direction it would much appreciated 🙂
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
An array is a primitive structure. It is sequential memory and allocated by the JVM.
An arraylist uses an array behind it, but you don’t have direct access to it. It can “grow” while a regular array cannot.
Basically, an arraylist starts (by default) with an array of length 10 behind it, and a count of 0. So imagine you had
behind this is an array like this
When you go
myInts.add(5);it does thisIf you added more you could get this
And if you added one more (which would push it beyond its capacity) it would make a new array to support it
You can change the size of the backing array if you want to. for example: