Get keys from HashMap in Java
Asked 07 September, 2021
Viewed 2.2K times
  • 59
Votes

I have a Hashmap in Java like this:

private Map<String, Integer> team1 = new HashMap<String, Integer>();

Then I fill it like this:

team1.put("United", 5);

How can I get the keys? Something like: team1.getKey() to return "United".

14 Answer