这篇博客是一些关于java数据结构零散的非系统记录:
1、HashMap 是无序不重复的。
2、IdentifyHashMap 是无序可重复的。但要注意的是,key值应该为不同的内存地址,如:
IdentityHashMap<String, String> map = new IdentityHashMap<String, String>();
map.put("aa", "first");
map.put("aa", "second");
map.put(new String("bb"), "third");
map.put(new String("bb"), "fourth");
for (Entry<String, String> entry : map.entrySet()) {
System.out.print(entry.getKey() + " ");
System.out.println(entry.getValue());
}
输出结果为:
"aa" "second"
"bb" "third"
"bb" "fourth"
3、LinkedHashMap 和 TreeHashMap 是有序的。