I need a data structure that provides key-value mappings, like a Map
, but that also allows me to fetch the key based on an (int) index (e.g. myKey = myDS.get(index)
), without having to iterate over the data structure to get the key at the desired index.
I thought of using LinkedHashMap
, but I don't see a way to get the key at a given index. Am I missing something in LinkedHashMap
? Or is there another data structure I can use?
EDIT:
This is not a duplicate. The correct answer to the other question is to use some sort of SortedMap
; however, that is not the correct answer to this question, since I'd like to be able to retrieve an Entry
from the data structure via an Integer
index, which is not supported in any Java library.