Get keys from HashMap in Java

后端 未结 14 2691
野的像风
野的像风 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 07:46

    Try this simple program:

    public class HashMapGetKey {
    
    public static void main(String args[]) {
    
          // create hash map
    
           HashMap map = new HashMap();
    
          // populate hash map
    
          map.put(1, "one");
          map.put(2, "two");
          map.put(3, "three");
          map.put(4, "four");
    
          // get keyset value from map
    
    Set keyset=map.keySet();
    
          // check key set values
    
          System.out.println("Key set values are: " + keyset);
       }    
    }
    

提交回复
热议问题