Lesson Overview

Welcome aboard our Java Voyage! Today, we're learning about ArrayLists. They're similar to arrays but can resize dynamically and also have many additional ways to simplify our lives. By the end, you'll know how to create and manipulate an ArrayList and understand when it's preferable to use arrays.

Creating an ArrayList in Java

ArrayLists are akin to a flexible roster of interstellar explorers; their size changes as we encounter or lose crew members. ArrayLists, part of Java's Collections Framework, elevate arrays to another level by providing more flexibility.

Constructing an ArrayList is akin to assembling a crew list. As shown, we declare a variable of type ArrayList:

Here:

  • List<Integer> is a general type for all lists of integers
  • crewMembers is a list name
  • new ArrayList<>() creates an instance of the list of integers. Note the part denoting that can be of any type ( etc.), but we already specified the type when mentioning it'd be at the beginning of the definition.
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal