Web / Apache Commons Collections Interview questions
What is an OrderedMap in Apache Commons Collections?
An OrderedMap<K,V> extends the plain Map interface with the guarantee that entries can be walked in a defined, stable order, plus navigation methods like firstKey(), lastKey(), nextKey(K), and previousKey(K).
OrderedMap<String, Integer> scores = new LinkedMap<>(); scores.put("Ann", 90); scores.put("Ben", 85); System.out.println(scores.firstKey()); // "Ann" System.out.println(scores.nextKey("Ann")); // "Ben"
LinkedMap preserves insertion order (similar in spirit to LinkedHashMap but with the extra navigation methods), while ListOrderedMap decorates any Map to add ordered iteration on top of it.
OrderedMap is handy when code needs to step forward/backward through entries explicitly, not just iterate them once from start to end.
More Related questions...