LinkedHashMap与HashMap
来源:互联网 发布:淘宝和天猫软件的区别 编辑:程序博客网 时间:2024/06/13 03:57
顾名思义LinkedHashMap是比HashMap多了一个链表的结构。与HashMap相比LinkedHashMap维护的是一个具有双重链表的 HashMap,LinkedHashMap支持2中排序一种是插入排序,一种是使用排序,最近使用的会移至尾部例如 M1 M2 M3 M4,使用M3后为 M1 M2 M4 M3了,LinkedHashMap输出时其元素是有顺序的,而HashMap输出时是随机的,如果Map映射比较复杂而又要求高效率的话,最好使用 LinkedHashMap,但是多线程访问的话可能会造成不同步,所以要用Collections.synchronizedMap来包装一下,从而实现同步。其实现一般为:Map<String String> map = Collections.synchronizedMap(new LinkedHashMap(<String String));
System.out.println("*************************LinkedHashMap*************");
Map<Integer, String> map = new LinkedHashMap<Integer, String>();
map.put(6, "apple");
map.put(3, "banana");
map.put(2, "pear");
// for (Iterator it = map.keySet().iterator(); it.hasNext();) {
// Object key = it.next();
// System.out.println(key + "=" + map.get(key));
// }
for(Map.Entry<Integer, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
System.out.println("*************************HashMap*************");
Map<Integer, String> map1 = new HashMap<Integer, String>();
map1.put(6, "apple");
map1.put(3, "banana");
map1.put(2, "pear");
for (Iterator it = map1.keySet().iterator(); it.hasNext();) {
Object key = it.next();
System.out.println(key + "=" + map1.get(key));
}
- LinkedHashMap与HashMap
- LinkedHashMap与HashMap
- HashMap与LinkedHashMap知识
- LinkedHashMap 与 HashMap
- 【转】LinkedHashMap与HashMap
- HashMap与LinkedHashMap
- HashMap与LinkedHashMap重要知识点
- 转:关于HashMap与LinkedHashMap (记录)
- LinkedHashMap和HashMap的区别与联系
- Java HashMap与LinkedHashMap的区别
- Java的HashMap与LinkedHashMap异同
- HashMap,TreeMap与LinkedHashMap的实例
- java中的Hashmap与LinkedHashMap总结
- HashMap与LinkedHashMap实现简要说明
- HashMap,ConcurrentHashMap与LinkedHashMap的区别
- HashMap,LinkedHashMap和Hashtable类的深入剖析与理解
- Java HashMap(LinkedHashMap)与Hashset(LinkedHashSet)的排序
- HashMap、weakHashMap、LinkedHashMap和TreeMap四者区别与联系
- 【转】【Android游戏开发之二】剖析游戏开发用view还是surfaceView ?!
- squid作为反向代理(web缓存服务器)的应用
- gredview中全选按钮以及删除
- glibc之socket网络编程
- Scrum
- LinkedHashMap与HashMap
- sort 详细用法
- UVA 10301 Rings and Glue
- tree中checked父子集联动,每个组只能选一个且不能影响其他项
- JNI Hello World
- Android打电话流程
- js当中用三元运算符要用到()
- 看看这里面最关键的一句话是什么?
- 【庆祝】庆祝自己在没有人认识的角落里,偷偷开张。。。