Try this, it will print the keys in reverse insertion order:
ListIterator<Integer> iter =
new ArrayList<>(map.keySet()).listIterator(map.size());
while (iter.hasPrevious()) {
Integer key = iter.previous();
System.out.println(key);
}
You can also iterate by the reverse insertion order of entries:
ListIterator<Map.Entry<Integer, String>> iter =
new ArrayList<>(map.entrySet()).listIterator(map.size());
while (iter.hasPrevious()) {
Map.Entry<Integer, String> entry = iter.previous();
System.out.println(entry.getKey() + ":" + entry.getValue());
}