LinkedHashSet class

                                                 
    java.lang.Object                                            
     |                                           
     |--java.util.AbstractCollection                                        
         |                                       
         |--java.util.AbstractSet                                    
             |                                   
             |--java.util.HashSet                                
                 |                               
                 |--java.util.LinkedHashSet                            
                                                 

Hash table and linked list implementation of the Set interface, with predictable iteration order.

ConstructorSummary
LinkedHashSet()Creates a new, empty linked hash set with the default initial capacity (16) and load factor (0.75).
LinkedHashSet(Collection<? extends E> c) Creates a new linked hash set with the same elements as the specified collection.
LinkedHashSet(int initialCapacity)Creates a new, empty linked hash set with the specified initial capacity and the default load factor (0.75).
LinkedHashSet(int initialCapacity, float loadFactor)Creates a new, empty linked hash set with the specified initial capacity and load factor.

  import java.util.LinkedHashSet;

public class Main {

  public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();

    System.out.println("Size of LinkedHashSet : " + lhashSet.size());
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));

    System.out.println(lhashSet.size());

    lhashSet.remove(new Integer("1"));

    System.out.println(lhashSet.size());
  }
}

The output:


Size of LinkedHashSet : 0
3
2
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.