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()

Output

2.Clear Arraylist in java using removeAll()

Output

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

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn