The Java.util.LinkedList.clear() method is used to remove all the elements from a linked list. Using the clear() method only clears all the element from the list and not deletes the list. In other words we can say that the clear() method is used to only empty an existing LinkedList.
Parameters: This function does not accept any parameter.
Return Value: This method does not return any value.
Below program illustrate the Java.util.LinkedList.clear() method:
Original LinkedList:[Geeks, for, Geeks, 10, 20] List after clearing all elements:  After adding elements to empty list:[Geeks, for, Geeks]
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- LinkedList set() Method in Java
- HashMap in Java
- HashSet vs TreeSet in Java
- ShortBuffer allocate() method in Java With Examples
- IntBuffer duplicate() method in Java with Examples
- ShortBuffer compact() method in Java With Examples
- LongBuffer equals() method in Java
- IntBuffer array() method in Java
- IntBuffer hasArray() method in Java
- ShortBuffer arrayOffset() method in Java With Examples