How to clear Arraylist in java

To clear ArrayList in java we have 2 ways
1. void clear() – Clears all the elements that are present in the ArrayList

2. boolean removeAll(Collection<?> c) – Removes those elements that are passed in as param and are available in the ArrayList.

Now lets see some examples of these methods

1. Clear Arraylist in java using clear()


2.Clear Arraylist in java using removeAll()


Please check the Performance Difference in Using clear() Vs removeAll()