How to set view of the keys contained in HashMap in Java

1 Answer

0 votes
package javaapplication1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

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");

        Set st = hMap.keySet();
   
        Iterator itr = st.iterator();
        
        while(itr.hasNext())
            System.out.println(itr.next());
  }
}
  
/*
run:

1
2
3
4
5

*/

 



answered Sep 27, 2016 by avibootz

Related questions

1 answer 174 views
1 answer 129 views
1 answer 143 views
1 answer 145 views
1 answer 128 views
128 views asked Mar 14, 2021 by avibootz
1 answer 180 views
1 answer 144 views
144 views asked Oct 10, 2020 by avibootz
...