LinkedHashSet - add, contains, remove, size methods program in java





LinkedHashSet - add, contains, remove, size methods program.





import java.util.LinkedHashSet;
import java.util.Set;
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */
public class LinkedHashSetAddExample {
   public static void main(String args[]) {
          System.out.println("-----1. create Set---");
          Set<String> linkedLinkedHashSet = new LinkedHashSet<String>();
          System.out.println("\n-----2. adding elements in Set---");
          linkedLinkedHashSet.add("ankit");
          linkedLinkedHashSet.add("JavaMadeSoEasy");
          System.out.println("linkedLinkedHashSet ="+linkedLinkedHashSet);
         
          System.out.println("\n------3. contains element  ");
          System.out.println("linkedLinkedHashSet.contains = "+linkedLinkedHashSet.contains("ankit"));
          System.out.println("\n------4. Remove element at 1st index i.e. mittal");
          linkedLinkedHashSet.remove("ankit");
          System.out.println(linkedLinkedHashSet);
          System.out.println("linkedLinkedHashSet ="+linkedLinkedHashSet);
   }
}
/*OUTPUT
-----1. create Set---
-----2. adding elements in Set---
linkedLinkedHashSet =[ankit, JavaMadeSoEasy]
------3. contains element
linkedLinkedHashSet.contains = true
------4. Remove element at 1st index i.e. mittal
[JavaMadeSoEasy]
linkedLinkedHashSet =[JavaMadeSoEasy]
*/



RELATED LINKS>


HashSet - isEmpty, size and clear methods program


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


No comments:

Post a Comment