两个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