There are two ways to remove all elements of an ArrayList in Java, either by using clear() or by using the removeAll() method. Both methods are defined in the java.util.List and java.util.Collection interface, hence they are available not just to ArrayList but also to Vector or LinkedList etc. Both elements removes all objects from ArrayList but there is a subtle difference in how they do. The clear() method is straightforward, it traverse through the ArrayList and sets all indices to null, which means the ArrayList becomes empty and all elements become eligible to Garbage collection, provided there is no more references to them. The time taken by clear() method is in O(n), which means the bigger the arraylist the longer it will take to empty it.
Read more »