-3

I defined a hashmap as follows:

HashMap<String, List<String>> hashmap = new HashMap<String, List<String>>();

And I would like to retrieve the complete list of keys and print them. However, keySet() does not work for maps defined as <String, List<String>>

Set<String, List<String>> keys = hashmap.keySet();

How could I solve this problem?

Idos
  • 15,053
  • 14
  • 60
  • 75
Peter
  • 71
  • 6

1 Answers1

3

What you need is not the .keySet(), but rather the .entrySet():

Set<Map.Entry<String, List<String>>> keys = hashmap.entrySet();

More info:

Community
  • 1
  • 1
Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147