How to iterate through the values of HashMap in Java

1 Answer

0 votes
package javaapplication1;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

public class JavaApplication1 {

    public static void main(String[] args) {

        HashMap hMap = new HashMap();
   
        hMap.put("1", "Java");
        hMap.put("2", "C++");
        hMap.put("3", "C");
        hMap.put("4", "C#");
        hMap.put("5", "PHP");
        hMap.put("6", "JavaScript");
        
        Collection cl = hMap.values();

        Iterator itr = cl.iterator();
   
        while(itr.hasNext())
            System.out.println(itr.next());
  }
}
  
/*
run:

Java
C++
C
C#
PHP
JavaScript

*/

 



answered Sep 27, 2016 by avibootz

Related questions

1 answer 129 views
1 answer 149 views
1 answer 168 views
1 answer 210 views
2 answers 245 views
2 answers 226 views
226 views asked Jan 21, 2022 by avibootz
...