import Java.util.HashMap;
public class Map_putAllTest {
public static void main(String[] args){
//两个map具有不同的key
HashMap map1=new HashMap();
map1.put("1", "A");
HashMap map2 = new HashMap();
map2.put("2", "B");
map2.put("3", "C");
map1.putAll(map2);
System.out.println(map1);
//两个map具有重复的key
HashMap map3=new HashMap();
map3.put("1", "A");
HashMap map4 = new HashMap();
map4.put("1", "B");
map4.put("3", "C");
map3.putAll(map4);
System.out.println(map3);
}
}
/* 输出结果:
* {3=C, 2=B, 1=A}
* {3=C, 1=B}
* 结论:putAll可以合并两个MAP,只不过如果有相同的key那么用后面的覆盖前面的
继续阅读与本文标签相同的文章
-
什么是网络爬虫?有什么用?怎么爬?终于有人讲明白了
2026-05-18栏目: 教程
-
11个点让你的Spring Boot启动更快
2026-05-18栏目: 教程
-
2019年9月份 阿里云域名优惠口令汇总
2026-05-18栏目: 教程
-
《安全说道》第三期 | 你家“大门”关好了吗?猪猪侠有话说
2026-05-18栏目: 教程
-
为什么支付宝有这么多“原生”技术牛人?
2026-05-18栏目: 教程
