The ArrayList class in Java is a part of the Java Collections Framework. It provides resizable-array implementation of the List interface. Java ArrayList allows us to randomly access the list, as it implements the RandomAccess interface.
Below is a table that lists the methods available in the Java ArrayList class. Each method link provides detailed information and examples. Click on each method to explore more with practical examples that illustrate its usage.
Method | Description |
---|---|
Java ArrayList add() Method | Adds an element to the list. |
Java ArrayList addAll() Method | Adds all elements from a specified collection to the list. |
Java ArrayList addFirst() Method | Adds an element to the beginning of the list. |
Java ArrayList addLast() Method | Adds an element to the end of the list. |
Java ArrayList clear() Method | Removes all elements from the list. |
Java ArrayList clone() Method | Returns a shallow copy of the list. |
Java ArrayList contains() Method | Checks if the list contains a specified element. |
Java ArrayList ensureCapacity() Method | Increases the capacity of the list. |
Java ArrayList equals() Method | Compares the list with another object for equality. |
Java ArrayList forEach() Method | Performs the given action for each element of the list. |
Java ArrayList get() Method | Returns the element at the specified position in the list. |
Java ArrayList getFirst() Method (introduced in Java 21) | Returns the first element in the list. |
Java ArrayList getLast() Method (introduced in Java 21) | Returns the last element in the list. |
Java ArrayList indexOf() Method | Returns the index of the first occurrence of the specified element. |
Java ArrayList isEmpty() Method | Checks if the list is empty. |
Java ArrayList iterator() Method | Returns an iterator over the elements in the list. |
Java ArrayList lastIndexOf() Method | Returns the index of the last occurrence of the specified element. |
Java ArrayList listIterator() Method | Returns a list iterator over the elements in the list. |
Java ArrayList removeAll() Method | Removes all elements from the list that are contained in the specified collection. |
Java ArrayList removeFirst() Method (introduced in Java 21) | Removes the first element from the list. |
Java ArrayList removeIf() Method | Removes all elements of the list that satisfy the given predicate. |
Java ArrayList removeLast() Method (introduced in Java 21) | Removes the last element from the list. |
Java ArrayList removeRange() Method | Removes elements from the list that are within the specified range. |
Java ArrayList retainAll() Method | Retains only the elements in the list that are contained in the specified collection. |
Java ArrayList set() Method | Replaces the element at the specified position in the list with the specified element. |
Java ArrayList spliterator() Method | Creates a Spliterator over the elements in the list. |
Java ArrayList subList() Method | Returns a view of the portion of the list between the specified fromIndex, inclusive, and toIndex, exclusive. |
Java ArrayList toArray() Method | Returns an array containing all elements in the list. |