clear in  Java LinkedHashSet Example

clear in Java LinkedHashSet Example


Posted in : Java Posted on : December 8, 2010 at 5:45 PM Comments : [ 0 ]

This Java Example shows how to remove all elements exists in Linked HashSet.

clear in  Java LinkedHashSet Example

This Java Example shows how to remove all elements exists in Linked HashSet. To remove all the elements exists in Linked HashSet We use clear() method of Linked HashSet class.  It removes all the elements stored in the specified object within the collection. To check that specified Linked HashSet object is empty or not we use boolean isEmpty() method of the Linked HashSet class. This method returns true if the object is empty otherwise returns false.

Example:- RemoveAllInLinkedHashSet.java

package devmanuals.com;

import java.util.*;

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

		LinkedHashSet LHSet = new LinkedHashSet();
		LHSet.add("C");
		LHSet.add("A");
		LHSet.add("B");
		LHSet.add("E");
		LHSet.add("F");
		LHSet.add("D");
		System.out.println("The LinkedHashSet elements are: " + LHSet);
		LHSet.clear();
		boolean b1 = LHSet.isEmpty();
		System.out.println("The LinkedHashSet is Empty : " + b1);
		System.out.println("The Elements are: " + LHSet);

	}
}

Output:-

The LinkedHashSet elements are: [C, A, B, E, F, D]

 The LinkedHashSet is Empty : true 

The Elements are: []

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics