Remove All Elements of Java LinkedList Example

Remove All Elements of Java LinkedList Example


Posted in : Java Posted on : November 29, 2010 at 5:42 PM Comments : [ 0 ]

This Java Example shows how to remove all the elements from the specified LinkedList object in java.

Remove All Elements of Java LinkedList Example

This Java Example shows how to remove all the elements from the specified LinkedList object  in java. To remove all of the elements from LinkedList object we use void clear() method. 

 Example: RemoveAllElementsLinkedList.java

package devmanuals.com;

import java.util.*;

public class RemoveAllElementLinkedList {
	public static void main(String[] args) {

		LinkedList LKLST = new LinkedList();
		LKLST.add("Gyan");
		LKLST.add("Singh");
		LKLST.add("Arunesh");
		LKLST.add("Kumar");
		System.out.println("The LinkedList Elements are : " + LKLST);
		LKLST.clear();
		System.out.println("The LinkedList Elements after removal : " + LKLST);

	}
}

Output:

The LinkedList Elements are : [Gyan, Singh, Arunesh, Kumar] 

The LinkedList Elements after removal : []

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics