How to clear an ArrayList in Java

By | August 9, 2020

How to clear an ArrayList in Java:

We can use java.util.List.clear() and removeAll() methods to clear elements from an ArrayList.

1. Empty an ArrayList using clear() method:


It removes all of the elements from the list. The list will be empty after this call returns.




2. Empty an ArrayList using removeAll() method:

Removes from this list all of its elements that are contained in the specified collection. It returns true if this list changed as a result of the call. Otherwise returns false.




Recommended Posts:

How to remove an element from an ArrayList

How to convert a String to String array in Java

Java interview questions for QA

SQL quick reference for interview preparation

Real-time selenium interview questions



Tags: How to clear an ArrayList in Java

arrays tostring in java | selenium interview questions | binary search






Play & Win contest by Selenium99

Home 1


Leave a Reply

Your email address will not be published. Required fields are marked *