Collection clear() method in Java with Examples
The clear() of java.util.Collection interface is used to clear the Collection upon which it is called. This method does not take any parameter and does not returns any value.
Parameters: This method do not accept any parameter
Return Value: This method does not return any value.
Exceptions: This method throws following exceptions:
- UnsupportedOperationException: if the add operation is not supported by this collection
Below examples illustrate the Collection clear() method:
Example 1: Using LinkedList Class
The list is: [Geeks, for, Geeks] The new List is: 
Example 2: Using ArrayDeque Class
ArrayDeque: [Welcome, To, Geeks, 4, Geeks] The new ArrayDeque is: 
Example 3: Using ArrayList Class
ArrayList: [15, 20, 25] The new ArrayList is: 
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.