3

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.

1
  • Sounds like you need a bidirectional map (key -> value, value -> key) Commented Aug 12, 2009 at 20:57

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.