Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,862 questions

51,784 answers

573 users

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 118 views
1 answer 130 views
1 answer 155 views
1 answer 197 views
2 answers 196 views
2 answers 192 views
192 views asked Jan 21, 2022 by avibootz
...