Many times we want to reset an ArrayList for the reusing purpose, by resetting we mean clearing it or removing all elements. There are two ways to reset an ArrayList in Java, by using the clear() method or calling removeAll(). If your ArrayList is small enough like it contains only 10 or 100 elements then you can use any of these two methods without worrying too much, but, if you have a huge list of lots of objects like an ArrayList containing 10M entries, then the choice of clear() vs removeAll() can make a huge difference in the performance of your Java application.
How to empty an ArrayList in Java? clear() vs removeAll() method Example Tutorial
August 03, 2022
0