Example:
package com.w3schools;
import java.util.Iterator;
import java.util.LinkedHashSet;
public class Test {
public static void main(String args[]){
//Create LinkedHashSet
LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();
//Add elements to LinkedHashSet
linkedHashSet.add("Jai");
linkedHashSet.add("Mahesh");
linkedHashSet.add("Vikas");
linkedHashSet.add("Sahil");
linkedHashSet.add("Sachin");
linkedHashSet.add("Vijay");
Iterator<String> iterator = linkedHashSet.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
} |
package com.w3schools;
import java.util.Iterator;
import java.util.LinkedHashSet;
public class Test {
public static void main(String args[]){
//Create LinkedHashSet
LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();
//Add elements to LinkedHashSet
linkedHashSet.add("Jai");
linkedHashSet.add("Mahesh");
linkedHashSet.add("Vikas");
linkedHashSet.add("Sahil");
linkedHashSet.add("Sachin");
linkedHashSet.add("Vijay");
Iterator<String> iterator = linkedHashSet.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
}
Output
Jai
Mahesh
Vikas
Sahil
Sachin
Vijay |
Jai
Mahesh
Vikas
Sahil
Sachin
Vijay