javacavaj
javacavaj

Reputation: 2971

Java - Collection with LinkedHashMap Attributes

Is there a collection class that has the LinkedHashMap quality of a predictable iteration order, but at the same time being indexable? LinkedHashMap implements a get() method, which returns the value object, but an indexof() method is not available. I'd like both.

Thanks.

Upvotes: 3

Views: 1117

Answers (2)

L. Cornelius Dol
L. Cornelius Dol

Reputation: 64036

I have such a thing, a Linked Tree Map free and unencumbered on my website. It sounds close to what you want.

Upvotes: 1

Steve B.
Steve B.

Reputation: 57324

A SortedMap (ConcurrentSkipListMap, TreeMap) has methods that will return submap views of all keys > (or <) the passed in key. So

index(key) == sortedMap.headMap(key).size();

Not likely to be terribly efficient.

Upvotes: 0

Related Questions