LinkedHashSet - isEmpty, size and clear methods program





LinkedHashSet - isEmpty, size and clear methods program.





import java.util.LinkedHashSet;
import java.util.Set;
/**
* Copyright (c), AnkitMittal JavaMadeSoEasy.com
*/
public class LinkedHashSetExample {
   public static void main(String args[]) {
          // creates array with initial capacity of 10.
          Set<String> linkedLinkedHashSet = new LinkedHashSet<String>();
          System.out.println("--------add element ");
          linkedLinkedHashSet.add("ankit");
          linkedLinkedHashSet.add("mittal");
          linkedLinkedHashSet.add("javaMadeSoEasy");
          System.out.println("linkedLinkedHashSet = "+linkedLinkedHashSet);
          System.out.println("linkedLinkedHashSet.isEmpty() = "+linkedLinkedHashSet.isEmpty());
          System.out.println("\n--------clear list - remove all elements from set");
          linkedLinkedHashSet.clear();
         
          System.out.println("linkedLinkedHashSet.isEmpty() = "+linkedLinkedHashSet.isEmpty());
          System.out.println("linkedLinkedHashSet = "+linkedLinkedHashSet);
         
   }
}
/*OUTPUT
--------add element
linkedLinkedHashSet = [ankit, mittal, javaMadeSoEasy]
linkedLinkedHashSet.isEmpty() = false
--------clear list - remove all elements from set
linkedLinkedHashSet.isEmpty() = true
linkedLinkedHashSet = []
*/



RELATED LINKS>


HashSet - iterate using iterator, Enumeration and enhanced for loop program


HashSet - fail-safe or fail-fast iteration using iterator, Enumeration and enhanced for loop program


HashSet - synchronizing using Collections.synchronizedSet program


HashSet - making set unmodifiable using Collections.unmodifiableSet


CopyOnWriteArraySet - add, contains, remove, size methods program


eEdit
Must read for you :