System.debug sorts values.
Use:
for (String key : myMap.keyset()) {
System.debug(key);
}
And you will see values as they were put into a Map.
Since comments below suggest that I am wrong please run this code as anonymous apex:
Map<String, String> users = new Map<String,String>();
users.put('Mike', 'Mith');
users.put('Adam', 'Adler');
users.put('Zenon', 'Ziber');
users.put('Peter', 'Portland');
System.debug('users.keySet() passed to System.debug is sorted A to Z.');
System.debug(users.keySet());
System.debug('Iterating over users.keySet() give us records in insert order.');
for (String firstName : users.keySet()) {
System.debug(firstName);
}
With API v59 I am getting such result:
11:54:00.28 (29524300)|USER_DEBUG|[8]|DEBUG|users.keySet() passed to System.debug is sorted A to Z.
11:54:00.28 (29642752)|USER_DEBUG|[9]|DEBUG|{Adam, Mike, Peter, Zenon}
11:54:00.28 (29659913)|USER_DEBUG|[11]|DEBUG|Iterating over users.keySet() give us records in insert order.
11:54:00.28 (29846066)|USER_DEBUG|[13]|DEBUG|Mike
11:54:00.28 (29867216)|USER_DEBUG|[13]|DEBUG|Adam
11:54:00.28 (29878237)|USER_DEBUG|[13]|DEBUG|Zenon
11:54:00.28 (29887848)|USER_DEBUG|[13]|DEBUG|Peter