I was wondering how Java orders items in the
Map
(HashMap
orHashtable
) when they are added. Are the keys ordered by the hashcode, memory reference or by allocation precedence...?It's because I've noticed same pairs in the
Map
are not always in the same order
I get a dictionary with a list of IDs and values like:
dict = {
GUID1=> {...},
GUID2=> {...},
GUID3=> {...},
}
The list is sorted by datetime (a field inside the {...}.
I need to read only the last 10 entries. So I tried to get the key array with dict.keys( ) and loop over it. But this key list is not sorted like the dictionary. The keys are GUIDs and that's why I can't sort by it.
And the dictionary I can only access by key, not by index - or is it possible?
Has anyone an example how to access the dictionary by index - or if it's possible to get the key array in same order like the dictionary.
Many thanks.