Iterate through the values of LinkedHashMap - Java Collection Framework

Java examples for Collection Framework:LinkedHashMap

Description

Iterate through the values of LinkedHashMap

Demo Code


import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Iterator;
 
public class Main {
 
  public static void main(String[] args) {
   //from  ww w  .  ja  v a2  s  . c o m
    LinkedHashMap lHashMap = new LinkedHashMap();
   
    //add key value pairs to LinkedHashMap
    lHashMap.put("1","One");
    lHashMap.put("2","Two");
    lHashMap.put("3","Three");
   
    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());
  }
}

Result


Related Tutorials