I need some kind of card, available in two directions, so with a key-key instead of a key value. Does it exist in Java? If not, what is the best way to create it?
So an example:
mySpecialHashMap.put("key1", "key2"); mySpecialMap.getL2R("key1") returns "key2"; mySpecialMap.getR2L("key2") returns "key1";
So you need a bi-directional map. You can use Apache Commons Collectionments BidiMap or Google Collections BiMap for this.
You can look at BiMap from Guava (formerly known as Google Collections).
, HashBiMap "mySpecialHashMap":
BiMap<String, String> myBiMap = HashBiMap.create(); myBiMap.put("key1", "key2"); myBiMap.get("key1"); // returns "key2" myBiMap.inverse().get("key2"); // returns "key1"
Yes, there is BiMap from Google Collections.
Or see. For reversible transfers fooobar.com/questions/638951 / ... .