Web / Apache Commons Collections Interview questions
What is a MultiKeyMap in Apache Commons Collections?
MultiKeyMap<K,V> lets you look values up using a combination of two to five key components instead of a single key object, without manually nesting Maps.
MultiKeyMap<String, Double> distances = new MultiKeyMap<>(); distances.put("NYC", "LA", 2451.0); double d = distances.get("NYC", "LA"); // 2451.0
Internally it combines the key components into a single MultiKey object with a composite hashcode, so a lookup across all components is a single O(1) average operation rather than walking through a chain of nested maps.
It's a convenient alternative to writing your own Map<K1, Map<K2, V>> when the key is naturally a small fixed tuple, like a coordinate pair or a (region, category) combination.
More Related questions...