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>