我有这段代码:
private final static TreeMap<String, UserNotification> USER_NOTIFICATION_MAP = new TreeMap<String, UserNotification>();
//Filling the map using services
String idString = "1";
Iterator it = USER_NOTIFICATION_MAP.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry)it.next();
idString = pairs.getKey().toString();
System.out.println(idString);
}
对于以下键值对的地图: 2 - 用户通知, 3 - 用户通知, 4 - 用户通知, 5 - 用户通知, 6 - 用户通知, 7 - 用户通知, 8 - 用户通知, 9 - 用户通知, 10 - 用户通知
代码的输出是: 10 2 3 4 5 6 7 8 9
考虑到TreeMap按其键对所有数据进行排序,这怎么可能呢?我想键值为10的应该在列表末尾。