Can I swap the keys of two values of a Hashmap, or do I need to do something clever?
Something that would look something like this:
Map.Entry<Integer, String> prev = null;
for (Map.Entry<Integer, String> entry: collection.entrySet()) {
if (prev != null) {
if (entry.isBefore(prev)) {
entry.swapWith(prev)
}
}
prev = entry;
}