Java HashMap key value storage and retrieval

后端 未结 7 1217
眼角桃花
眼角桃花 2020-12-23 22:27

I want to store values and retrieve them from a Java HashMap.

This is what I have so far:

public void processHashMap()
{
    HashMap hm = new HashMap         


        
相关标签:
7条回答
  • 2020-12-23 22:57

    You can use keySet() to retrieve the keys. You should also consider adding typing in your Map, e.g :

    Map<Integer, String> hm = new HashMap<Integer, String>();
    hm.put(1,"godric gryfindor");
    hm.put(2,"helga hufflepuff"); 
    hm.put(3,"rowena ravenclaw");
    hm.put(4,"salazaar slytherin");
    
    Set<Integer> keys = hm.keySet();
    
    0 讨论(0)
提交回复
热议问题