VOOZH about

URL: https://www.geeksforgeeks.org/java/arraylist-clear-method-in-java-with-examples/

⇱ ArrayList clear() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ArrayList clear() Method in Java with Examples

Last Updated : 11 Jul, 2025

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.


Output
[10, 20, 30]
[]

Syntax of clear() Method

public void clear()

  • Parameter: The clear() method does not need any parameters.
  • Return Type: It does not return any value as it removes all the elements in the list and makes it empty. 

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.


Output
[Dog, Cat, Rabbit]
[]


Example 3: Here, we will use the clear() method to clear elements from an ArrayList of Objects.


Output
[Ram, Shyam]
[]
Comment