-2

I am currently learning Java, having had experience in Python already. I understand that the closest thing to Python dictionaries in Java is HashMap and I am curious if there is a HashMap equivalent for Python's dict.items()/dict.values()/dict.keys() - I understand HashMap has a get() method but I want to retrieve values without knowing the keys of the Map.

If there is no equivalent, how do you recommend I get around this problem? Do not use HashMap at all or?

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
pundadesh
  • 43
  • 2
  • 3
    The `Map` available methods are described on [Map](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html) java doc page –  Jan 19 '19 at 18:12
  • What does "retrieve items without knowing the keys" mean? You can get all the values as a collection. Is that what you want? – duffymo Jan 19 '19 at 18:13
  • 3
    The current behavior of those Python methods was actually [*based on*](https://www.python.org/dev/peps/pep-3106/) the corresponding Java methods. – user2357112 Jan 19 '19 at 18:15
  • Please read [the docs](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Map.html) first, then ask here whenever you find a problem you cannot solve. – fps Jan 19 '19 at 19:13

1 Answers1

7

Map.entrySet(), Map.values(), Map.keySet(). Take a look at Map javadoc which lists all the methods in Map interface and what is their role.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111