A
Andreas Leitgeb
Given a LinkedHashMap instance, what would be a
reasonable way to obtain the latest added key?
The specific definition of "reasonable" being:
- no separate keeping track of key-sequence
- it should be a O(1) operation, and not
have to iterate all keys.
Unlike TreeMap, the LinkedHashMap doesn't implement
NavigableMap.
If nothing else helps, I'll need to switch to a LinkedList,
and thereby sell the "O(1)" of searching for an Object (by
key) in exchange for a "O(1)" of obtaining the last Object.
It just seems odd to me, that a LinkedHashMap doesn't
have such a nobrainer getter, or, that a LinkedHashMap
isn't also a NavigableMap with the natural ordering
induced by position.
reasonable way to obtain the latest added key?
The specific definition of "reasonable" being:
- no separate keeping track of key-sequence
- it should be a O(1) operation, and not
have to iterate all keys.
Unlike TreeMap, the LinkedHashMap doesn't implement
NavigableMap.
If nothing else helps, I'll need to switch to a LinkedList,
and thereby sell the "O(1)" of searching for an Object (by
key) in exchange for a "O(1)" of obtaining the last Object.
It just seems odd to me, that a LinkedHashMap doesn't
have such a nobrainer getter, or, that a LinkedHashMap
isn't also a NavigableMap with the natural ordering
induced by position.