Skip to content

Java Arrays and ArrayLists

Intermediate

Arrays and ArrayLists are the fundamental data structures for storing collections of elements in Java. An array is a fixed-size, ordered collection of elements of the same type, declared with bracket notation (int[] arr = new int[5]) and accessed by zero-based index. Arrays support efficient random access but cannot be resized after creation.

ArrayLists are part of the java.util package and provide a resizable alternative to arrays. They store objects (not primitives), support dynamic sizing with methods like add(), remove(), get(), set(), and size(), and handle autoboxing for primitive wrapper types. Understanding when to use arrays versus ArrayLists is a key design decision in Java programming.

This topic also covers array traversal using standard for loops and enhanced for-each loops, common algorithms (searching, finding min/max, summing, reversing), 2D arrays for tabular data, and the important distinction between passing arrays by reference versus passing primitives by value. These concepts form the foundation of AP Computer Science A Units 6 and 7, comprising 10-15% of the AP exam.

Practice a little. See where you stand.

Ready to practice?5 minutes. No pressure.

Key Concepts

One concept at a time.

Explore your way

Choose a different way to engage with this topic — no grading, just richer thinking.

Explore your way — choose one:

Explore with AI →
Curriculum alignment— Standards-aligned

Grade level

Grades 9-12College+

Learning objectives

  • Declare, initialize, and access elements in one-dimensional arrays using zero-based indexing
  • Traverse arrays using standard for loops and enhanced for-each loops to implement common algorithms
  • Create and manipulate ArrayLists using add, get, set, remove, and size methods
  • Explain autoboxing and unboxing between primitive types and wrapper classes
  • Declare and traverse 2D arrays using nested loops for row-by-row and column-by-column access

Recommended Resources

This page contains affiliate links. We may earn a commission at no extra cost to you.

Books

Barron's AP Computer Science A

by Roselyn Teukolsky

Head First Java

by Kathy Sierra and Bert Bates

Courses

AP Computer Science A

CourseraEnroll
Java Arrays and ArrayLists - Learn, Quiz & Study | PiqCue