Java ArrayList remove() and removeAll() - Example Tutorial

In this Java ArrayList tutorial, you will learn how to remove elements from ArrayList in Java e.g. you can remove String from ArrayList of String or Integer from ArrayList of Integers. There are actually two methods to remove an existing element from ArrayList, first by using the remove(int index) method, which removes elements with given index, remember index starts with zero in ArrayList. So a call to remove(2) in an ArrayList of {"one", "two", "three"} will remove 3rd element which is "three". The second method to remove element is remove(Object obj), which removes given object from ArrayList. For example, a call to remove("two") will remove the second element from ArrayList. Though you should remember to use Iterator or ListIterator remove() method to delete elements while iterating, using ArrayList's remove methods, in that case, will throw ConcurrentModificationException in Java.
Read more »