Get keys from HashMap in Java

后端 未结 14 2637
野的像风
野的像风 2020-12-04 07:03

I have a Hashmap in Java like this:

private Map team1 = new HashMap();

Then I fill it like th

14条回答
  •  独厮守ぢ
    2020-12-04 08:04

    public class MyHashMapKeys {
    
        public static void main(String a[]){
            HashMap hm = new HashMap();
            //add key-value pair to hashmap
            hm.put("first", "FIRST INSERTED");
            hm.put("second", "SECOND INSERTED");
            hm.put("third","THIRD INSERTED");
            System.out.println(hm);
            Set keys = hm.keySet();
            for(String key: keys){
                System.out.println(key);
            }
        }
    }
    

提交回复
热议问题