Member-only story

Java Programming Language Tutorial: Intro to ArrayLists

Jesse L
4 min readApr 5, 2022

--

Hi everyone, welcome back. In this tutorial, we will be going over ArrayLists in Java. ArrayLists can be used to store a collection of data, similar to that of an array. The key difference between an ArrayList and an array is that an ArrayList is resizable and an array is not. This leaves the ArrayList as a great option when wanting to modify a collection of data. With this introduction out of the way, let’s get into it.

Creating ArrayList

Let’s start by creating an ArrayList. Before we can create the ArrayList, we need to make sure we have our ArrayList import, which is included within the java.util package:

import java.util.ArrayList;

Now we can successfully create our ArrayList:

ArrayList<Integer> numbers = new ArrayList<Integer>();

So now, we have created an ArrayList variable of the integer type named numbers. When we create our ArrayList, we need to specify the data type. As we can see in the example above, we have used the ‘Integer’ data type. We can use other data types as well, such as the String data type.

Adding Elements Into The ArrayList

Now, let’s try to add elements into our ArrayList. We can do this by using the built in…

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet