How to remove elements from ArrayList

In this post we will see various ways to remove elements from ArrayList in java.

ArrayList provides following methods to remove elements.

1. E remove(int index)

Removes an element from the specified position in the arrayList

Example

Output

2. boolean remove(Object o)

Removes the first occurrence of element from the arrayList

Example

Output

3. boolean removeAll(Collection<?> c)

Removes list of element from the ArrayList that are available in the collection.

Example

Output

Reference

1. ArrayList