ArrayList Methods Reference - Complete Reference with Syntax and Description
ArrayList Methods Reference - Complete Reference with Syntax and Description
Explore the complete list of Java ArrayList methods with code syntax and beginner-friendly explanations. Perfect for learners and developers.
This reference explains ArrayList Methods Reference - Complete Reference with Syntax and Description through its syntax, examples and boundaries. Use the linked course lessons when the surrounding Java concepts are unfamiliar.
Use this reference
Identify the documented behavior, read a complete example and check its inputs before applying it.
Java ArrayList Methods
- add()
Adds an element to the list or inserts it at a specified index.public boolean add(E e) public void add(int index, E element)- addAll()
Adds all elements from a collection to the list, optionally at a given position.public boolean addAll(Collection extends E> c) public boolean addAll(int index, Collection extends E> c)- clear()
Removes all elements from the list, leaving it empty.public void clear()- clone()
Returns a shallow copy of the ArrayList.public Object clone()- contains()
Checks if the list contains a specific element.public boolean contains(Object o)- ensureCapacity()
Increases the capacity of the list to ensure it can hold more elements.public void ensureCapacity(int minCapacity)- forEach()
Applies an action to each element in the list.public void forEach(Consumer super E> action)- get()
Returns the element at the specified index.public E get(int index)- indexOf()
Returns the index of the first occurrence of the specified element.public int indexOf(Object o)- isEmpty()
Checks if the list has no elements.public boolean isEmpty()- iterator()
Returns an iterator to traverse the list.public Iteratoriterator() - lastIndexOf()
Returns the index of the last occurrence of the specified element.public int lastIndexOf(Object o)- listIterator()
Returns a list iterator for the list or from a specific index.public ListIteratorlistIterator() public ListIterator listIterator(int index) - remove()
Removes the element at the given index or removes the first occurrence of the specified element.public E remove(int index) public boolean remove(Object o)- removeAll()
Removes all elements that are also in the specified collection.public boolean removeAll(Collection> c)- removeIf()
Removes all elements that satisfy the given condition.public boolean removeIf(Predicate super E> filter)- removeRange()
Removes elements between the specified range of indexes.protected void removeRange(int fromIndex, int toIndex)- replaceAll()
Replaces each element using the specified operator.public void replaceAll(UnaryOperatoroperator) - retainAll()
Keeps only the elements that are also in the specified collection.public boolean retainAll(Collection> c)- set()
Replaces the element at the given index with a new one.public E set(int index, E element)- size()
Returns the number of elements in the list.public int size()- sort()
Sorts the list using the given comparator.public void sort(Comparator super E> c)- spliterator()
Creates a Spliterator for the list elements.public Spliteratorspliterator() - subList()
Returns a view of the portion of this list between fromIndex and toIndex.public ListsubList(int fromIndex, int toIndex) - toArray()
Returns an array containing all elements in this list.public Object[] toArray() publicT[] toArray(T[] a) - trimToSize()
Trims the capacity of the list to match its current size.public void trimToSize()
Using this reference
Check the example’s types, inputs and documented behavior before copying it into an application. Some APIs require external libraries, files or platform services; consult their setup notes.
Related explanations: Java Data Types - Primitive and Non-Primitive, Java Class - Blueprint of Objects, Exceptions in Java Introduction.
Supporting documentation: Official Java learning guide.
Reference checks are optional and do not count toward course progress.