ArrayList All Methods Complete Guide Syntax Examples Iterator List Collection Framework Tutorial

Robert Jul 13, 2026

An ArrayList in Java is a resizable-array implementation of the List interface, part of the Java Collection Framework. It's a popular choice for storing ordered collections of objects due to its flexibility and performance. Let's explore its methods, categorized for easier understanding.

Common Array Methods
Common Array Methods

ArrayLists have a wide range of methods that enable you to add, remove, access, and manipulate elements. Understanding these methods is key to leveraging the full potential of ArrayLists in your Java applications.

AP CSA ArrayList Methods | Java Study Guide
AP CSA ArrayList Methods | Java Study Guide

Adding and Removing Elements

ArrayLists offer several methods to add and remove elements from the list.

Java ArrayList Tutorial with Examples
Java ArrayList Tutorial with Examples

The add(E e) method append the specified element to the end of this list, while add(int index, E element) inserts the specified element at a particular position.

Adding Elements at Beginning and End

Data Science, Science
Data Science, Science

To add elements at the beginning of the list, use add(0, e), and to add at the end, use add(e).

To add multiple elements at once, use the addAll(Collection c) or addAll(int index, Collection c) methods.

Removing Elements

an array sheet with text and numbers on it
an array sheet with text and numbers on it

The remove(int index) method removes the element at the specified position, while remove(Object o) removes the first occurrence of the specified element from this list.

The removeAll(Collection c) method removes from this list all of its elements that are contained in the specified collection. Conversely, retainAll(Collection c) retains only the elements in this list that are contained in the specified collection.

Accessing and Manipulating Elements

an image of a computer screen with the text 7 array method in front of it
an image of a computer screen with the text 7 array method in front of it

ArrayLists provide various methods to access and manipulate the elements within the list.

The get(int index) method retrieves the element at the specified position, while set(int index, E element) replaces the element at the specified position with the given element.

Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
ArrayList Program in Java - Scientech Easy
ArrayList Program in Java - Scientech Easy
Java Collection Framework: ArrayList Explained Visually
Java Collection Framework: ArrayList Explained Visually
Array In Programming, Javascript Programming Language Facts, How To Learn Javascript Arrays, Advanced Javascript Coding Tips, Javascript Array Appending Tutorial, Javascript Array Find Method Example, Javascript Array Basics, Javascript Array Methods Tutorial, Advanced Javascript Coding Guide
Array In Programming, Javascript Programming Language Facts, How To Learn Javascript Arrays, Advanced Javascript Coding Tips, Javascript Array Appending Tutorial, Javascript Array Find Method Example, Javascript Array Basics, Javascript Array Methods Tutorial, Advanced Javascript Coding Guide
Array Data Structure Explained Simply
Array Data Structure Explained Simply
Array vs Linked List 🧠 Easy Data Structures Explained | Coding Notes
Array vs Linked List 🧠 Easy Data Structures Explained | Coding Notes
Day 1 of dsa - Arrays...
Day 1 of dsa - Arrays...
Infosys Prep – Arrays & Strings Problems
Infosys Prep – Arrays & Strings Problems
Data Science, Science
Data Science, Science

Accessing and Manipulating Elements

The size() method returns the number of elements in this list. To check if a list is empty, use isEmpty().

The contains(Object o) method returns true if this list contains the specified element. To find the index of the first occurrence of an element, use indexOf(Object o).

Swapping Elements

To swap the positions of two elements in an ArrayList, use Lists utility class from Apache Commons or Guava libraries, as Java's built-in ArrayList does not have a built-in method for this.

Here's an example using Apache Commons' Lists utility class: Lists.swap(list, i, j);

Sorting and Searching Elements

ArrayLists do not have built-in sorting or searching methods, as they are not designed to be sorted.

To sort an ArrayList, you can use Collections.sort utility method. To search for an element, you can use the indexOf method or implement a custom search algorithm.

Sorting an ArrayList

Here's how to sort an ArrayList using Collections.sort: ```java List list = new ArrayList<>(); // populate list... Collections.sort(list); ```

To sort in reverse order, use Collections.reverse.

In conclusion, ArrayLists in Java offer a wide range of methods for adding, removing, accessing, and manipulating elements, making them a powerful tool for working with ordered collections of objects. Mastering these methods will enable you to harness the full potential of ArrayLists in your Java applications. Happy coding!