ArrayList Class

This lesson provides some more detail on the built-in methods of the ArrayList class in Java.

We'll cover the following


ArrayList in Java provides us with dynamic arrays. It is similar to vectors in C++. The size of the arraylist can change; the size can increase if the collection grows or shrink if objects are removed from the collection. It also allows us to randomly access items from the list.

Some methods in the ArrayList are:

forEach() - performs the given action for element in the iterable.

contains(element) - Returns true if the list contains the specified element.

remove(index or element) - Removes the element at the specified position in this list or the first occurrence of the object specified.

get(index) - Returns the element at the specified position in the list.

size() - Returns the number of elements in the list.

listIterator​() - Returns a list iterator over the elements of the list.

isEmpty​() - Returns true if the list contains no elements.

add(element): insert the specified element at a specific position index in a list.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.