HashMap<String, String[]> content = new HashMap<String, String[]>();
content.put("Help", new String[]{"About"});
content.put("View", new String[]{"Grid"});
content.put("File", new String[]{"Import", "Export"});
for(String key : content.keySet()){
System.out.println(key);
}
上面的代码日志:HashMap的键集自动排序
View
Help
File
但是为什么这个排序?
运行两次,三次,更多..你会看到不同的结果。 –
偶然。添加更多的键,你会看到它没有排序。 – kiheru
重新启动了10次,但始终是相同的顺序。 –