Java Array Lists in 5 minutes

static vs dynamic arrays

JT Earl
3 min readMar 3, 2021

What is it?

In programming, there is a concept of static and dynamic arrays. We declare a static array in Java as a set size. I go into more details on static arrays in my Java array post. A dynamic array means we can initialize the array without a set size. The dynamic array will also grow as you add more items to the array. There are several different types of dynamic arrays in Java but this article will cover the ArrayList. I’ll cover how to initialize an ArrayList, some helpful methods, and the pros and cons of using them.

Photo by Kelly Sikkema on Unsplash

How to Initialize

In Java, all dynamic arrays implement an interface called List. When using dynamic arrays it’s considered a best practice to type the variable as List. This prevents getting coupled to a specific implementation of a list. If you’re curious you can read the Oracle documentation on what implementations of List are available. List requires a type, whatever the type is the only type we can store in the List. We now know enough to declare the first half of our ArrayList.

List<String> nameOfList;

To initialize our array list we’ll need to call the new keyword on the ArrayList class. When creating an ArrayList you…

--

--

JT Earl

Programmer Since 17. Currently working in front-end and mid-tier programming for a finance company. Check out my Tech blog @ documentobject.com