I have such code:
HashMap<Long, TempPosition> positions = getTempPositions();
    for (SortedMap.Entry<Long, TempPosition> p: positions.entrySet()) {...}
The problem is the 'positions' is not sorted or non valid sorted. What the easiest way to iterate through the hashmap and save its current order?
Thank you
A HashMap by definition doesn't have an order. If you need to preserve or create some kind of order you need to use TreeMap instead of HashMap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With