Web / Apache Commons Collections Interview questions
What is a BidiMap in Apache Commons Collections?
A BidiMap<K,V> is a Map that supports efficient lookup in both directions - by key, like a normal Map, and by value, using getKey(value).
To make reverse lookups unambiguous, a BidiMap enforces that values are also unique: putting a value that already exists under a different key removes that old mapping first.
BidiMap<String, Integer> map = new DualHashBidiMap<>(); map.put("one", 1); map.put("two", 2); System.out.println(map.get("one")); // 1 System.out.println(map.getKey(2)); // "two" BidiMap<Integer, String> inverse = map.inverseBidiMap();
Common implementations include DualHashBidiMap (two internal HashMaps) and DualTreeBidiMap (two internal TreeMaps for sorted iteration in both directions).
More Related questions...