Array vs. ArrayList (Java)

My favorite data structure is the ArrayList. Sure, it isn’t as fancy as a Hashmap, but it’s so simple and you can just add things to the end of the list easily. Arrays are taught fairly early in every computer scientists’ career in java. It’s a data structure of a fixed size to hold stuff in it like objects, integers, strings, etc. But what is an ArrayList? How’s it different from an array?

Look at the name. An ArrayList is a List. Think of a grocery list for Walmart that you jot down in a note pad. You can add things to the bottom of the list, add things in the middle of the list, and scratch things off the list. Similarly, you can do arrayList.add(object) to add to the end of the list, arrayList.add(2, object) to insert an object at index 2, and arrayList.remove(object) to remove that specific object from the list.

Leave a Reply

Your email address will not be published. Required fields are marked *