0

Is there a data structure which works like a two-way hashmap?

Specifically, a hashmap can map keys to values, and I would like it also be able to map values to keys, assuming the mapping from keys to values are bijective, so that the mapping has a reverse mapping.

I can have two data structures for the mapping and its reverse mapping. Is it a good idea?

I wonder if there is a single data structures for both?

In Java, is there a collection for that purpose?

Thanks.

  • https://stackoverflow.com/questions/1670038/does-java-have-a-hashmap-with-reverse-lookup – DeiAndrei Nov 24 '17 at 15:53
  • Afaik there's no data structure available in the JDK itself. However there are some in libraries like Apache Commons Collections or Google Guava. A basic structure wouldn't be too hard anyways: just use and maintain 2 maps. – Thomas Nov 24 '17 at 15:53
  • https://stackoverflow.com/questions/10699492/bi-directional-map-in-java – BackSlash Nov 24 '17 at 15:54

0 Answers0