1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* Iterate through elements of Java LinkedHashSet example This Java Example shows how to iterate through elements Java LinkedHashSet object. */ import java.util.LinkedHashSet; import java.util.Iterator; public class IterateThroughElementsOfLinkedHashSetExample { public static void main(String[] args) { //create object of LinkedHashSet LinkedHashSet lhashSet = new LinkedHashSet(); //add elements to LinkedHashSet object lhashSet.add(new Integer("1")); lhashSet.add(new Integer("2")); lhashSet.add(new Integer("3")); //get the Iterator Iterator itr = lhashSet.iterator(); System.out.println("LinkedHashSet contains : "); while(itr.hasNext()) System.out.println(itr.next()); } } /* Output would be LinkedHashSet contains : 1 2 3 */ |
Add Comment