我已经按照特定的顺序设置了一个HashMap,但它以奇怪的顺序被迭代!
请考虑下面的代码:
HashMap<String, String> map = new HashMap<String, String>();
map.put("ID", "1");
map.put("Name", "the name");
map.put("Sort", "the sort");
map.put("Type", "the type");
...
for (String key : map.keySet()) {
System.out.println(key + ": " + map.get(key));
}
以及结果:
Name: the name
Sort: the sort
Type: the type
ID: 1
我需要按照我放置条目的顺序进行迭代。
非常感谢任何帮助。