I found an interesting list organization.
In addition to List<Object> make Map<Object, Integer> . And if you need to get an object by index, then turn to List, and if you find out the index of the object, then climb into the Map.
So I got interested, but is it really faster or wasting RAM?
PS I remember the first exactly: ArrayList, but I don’t remember the second one. (I will add in the evening)

    1 answer 1

    Map and List are interfaces, so your question cannot be strictly answered without knowing which implementations are behind them. If you mean HashMap and ArrayList , then yes, with high probability, HashMap.get(obj) will be faster than the similar ArrayList.indexOf(obj) even if you have 10-20 elements. If you often need the operation indexOf , then this approach is justified. Although it is worth wondering why, in principle, you need such an operation. It may be worth rethinking the way data is organized.