Iterate through elements in LinkedHashSet in Java
Description
The following code shows how to iterate through elements in LinkedHashSet.
Example
//from w w w. jav a 2s . com
import java.util.Iterator;
import java.util.LinkedHashSet;
public class Main {
public static void main(String[] args) {
LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();
lhashSet.add(new Integer("1"));
lhashSet.add(new Integer("2"));
lhashSet.add(new Integer("3"));
Iterator itr = lhashSet.iterator();
while (itr.hasNext()){
System.out.println(itr.next());
}
}
}
The code above generates the following result.