VOOZH about

URL: https://www.geeksforgeeks.org/java/linkedlist-clear-method-in-java/

⇱ LinkedList clear() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedList clear() Method in Java

Last Updated : 11 Jul, 2025

In Java, the clear() is used to remove all the elements from a LinkedList. This method only clears all the element from the list and not deletes the list. After calling this method, the list will be empty.

Syntax of LinkedList clear() Method

void clear()

  • Parameters: This method does not accept any parameter.
  • Return type: This method does not return any value.

Example: Here, we use the clear() method to remove elements from the LinkedList.


Output
Original LinkedList: [Geeks, for, Geeks]
List after clearing all elements: []
Comment