![]() |
VOOZH | about |
The clear() method in the ArrayList class in Java is used to remove all elements from an ArrayList. After calling this method, the list becomes empty.
Example 1: Here, we will use the clear() method to clear elements from an ArrayList of Integers.
[10, 20, 30] []
public void clear()
Important Point: It does implement interfaces like Serializable, Cloneable, Iterable, Collection, List, RandomAccess.
Example 2: Here, we will use the clear() method to clear elements from an ArrayList of Strings.
[Dog, Cat, Rabbit] []
Example 3: Here, we will use the clear() method to clear elements from an ArrayList of Objects.
[Ram, Shyam] []