I have this Java Map:
Can you tell me how I can get the 6-th element of the Map?
private static final Map cache = new HashMap<
A HashMap
does not maintain the order of the elements inserted in it. You can used a LinkedHashMap
instead which maintains the order of the elements inserted in it.
Though you need to note that even a LinkedHashMap
has no such method which would give the element at a particular index. You will have to manually iterate through the entries and extract the element at the 6th iteration.