Log in from a computer to take this course

You'll need to log in from a computer to start Java: Loops and Arrays. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store

When we work with arrays in Java, we’ve been limited by the fact that once an array is created, it has a fixed size. We can’t add or remove elements.

But what if we needed to add to the book lists, newsfeeds, and other structures we were using arrays to represent?

To create mutable and dynamic lists, we can use Java’s ArrayLists. ArrayLists allow us to:

  • Store object references as elements
  • Store elements of the same type (just like arrays)
  • Access elements by index (just like arrays)
  • Add elements
  • Remove elements

Remember how we had to import java.util.Arrays in order to use additional array methods? To use an ArrayList at all, we need to import them from Java’s util package as well:

import java.util.ArrayList;

Let’s learn how to make use of this powerful object…



In Shopping.java we’ve defined two arrays:

  • groceryItems, a String array
  • prices, a double array

We’ve tried to add a new item to the end of each. Run the code — does it work?

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?