Remove specified element from LinkedHashSet - Java Collection Framework

Java examples for Collection Framework:LinkedHashSet

Description

Remove specified element from LinkedHashSet

Demo Code


import java.util.LinkedHashSet;
 
public class Main {
  public static void main(String[] args) {
    LinkedHashSet lhashSet = new LinkedHashSet();
   /*from w  ww.  j  a v  a2  s.com*/
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
   
    System.out.println("LinkedHashSet before removal : " + lhashSet);
   
    boolean blnRemoved = lhashSet.remove(new Integer("2"));
    System.out.println("Was 2 removed from LinkedHashSet ? " + blnRemoved);
   
    System.out.println("LinkedHashSet after removal : " + lhashSet);
  }
}

Result


Related Tutorials