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 37 38 39 40 41 42 43 |
/* Iterate through the values of Java LinkedHashMap example This Java Example shows how to iterate through the values contained in the LinkedHashMap object. */ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Iterator; public class IterateValuesOfLinkedHashMapExample { public static void main(String[] args) { //create LinkedHashMap object LinkedHashMap lHashMap = new LinkedHashMap(); //add key value pairs to LinkedHashMap lHashMap.put("1","One"); lHashMap.put("2","Two"); lHashMap.put("3","Three"); /* get Collection of values contained in LinkedHashMap using Collection values() method of LinkedHashMap class */ Collection c = lHashMap.values(); //obtain an Iterator for Collection Iterator itr = c.iterator(); //iterate through LinkedHashMap values iterator while(itr.hasNext()) System.out.println(itr.next()); } } /* Output would be One Two Three */ |
Add Comment