How to create a 2 way map in java

前端 未结 6 1601
无人共我
无人共我 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:29

    Apache Commons also includes the BidiMap (Bi Directional Map).

    Defines a map that allows bidirectional lookup between key and values.

    This extended Map represents a mapping where a key may lookup a value and a value may lookup a key with equal ease. This interface extends Map and so may be used anywhere a map is required. The interface provides an inverse map view, enabling full access to both directions of the BidiMap.

提交回复
热议问题