How to create a 2 way map in java

前端 未结 6 1626
无人共我
无人共我 2020-11-28 09:42

I need a data structure to store string-int value pairs in an 1:1 relationship, and being able too look up from either way their counterpart.

I wrote a class with a

6条回答
  •  星月不相逢
    2020-11-28 10:28

    Create a hashmap that maps Object to Object - then you can use the same map to store String -> Integer and Integer -> String.

    When you add a string/int pair just add it both ways to the same map.

提交回复
热议问题