两个map合并所用函数为:putAll
package myProject; import java.util.HashMap; import java.util.Map; public class TestMapMerge { public static void main(String[] args) { Map<String,Object> map1=new HashMap<String,Object>(); Map<String,Object> map2=new HashMap<String,Object>(); map1.put("a", "Hello"); map2.put("b", "world"); map1.putAll(map2); System.out.println(map1.get("a")+(String)map2.get("b")); } }
输出结果为:Helloworld
原文地址:https://www.cnblogs.com/BonnieWss/p/9228088.html
时间: 2024-11-10 16:25:13