Both hashed and indexed list or array?

Is there any class in Java that contains an array of elements in order and is optimized for quick searches?

those. I need to get elements with both a numerical index (e.g. c Vector) and a hash (e.g. c HashMap).

LinkedHashMap does not match

I think that LinkedHashMapdoes not match, since it guarantees order, but does not allow quick access by index (position number). According to the description, in order to find a given position, you will need to go through the whole chain. This is what anyone Collectionwith an iterator can do.

EDIT 2

those. both search by key and by index should be fast, and not just a key.

+5
source share
4

Map . a Map , . LinkedHashMap , , , - , - :

map.entrySet().toArray()[index] // mind the casts, etc.

, , , , , . , , , .

+2

LinkedHashMap. . , .

+1

, LinkedHashMap

:

A hash table and associated map interface list with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly linked list passing through all its entries. This linked list defines the iteration order, which is usually the order in which keys were inserted into the map (insert order). Please note that the insertion order does not change if the key is reinserted into the card. (The key k is reinserted into map m if m.put (k, v) is called when m.containsKey (k) returns true immediately before the call.)

+1
source