Remove all elements from LinkedHashSet - Java Collection Framework

Java examples for Collection Framework:LinkedHashSet

Description

Remove all elements from LinkedHashSet

Demo Code

 
import java.util.LinkedHashSet;
 
public class Main {
 
  public static void main(String[] args) {
    LinkedHashSet lhashSet = new LinkedHashSet();
   //from  w ww . ja  va2s. co  m
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
   
    System.out.println("LinkedHashSet before removal : " + lhashSet);
   
    lhashSet.clear();
    System.out.println("LinkedHashSet after removal : " + lhashSet);
   
    System.out.println("Is LinkedHashSet empty ? " + lhashSet.isEmpty());    
  }
}

Result


Related Tutorials