两个map合并所用函数为:putAll
package myProject;import java.util.HashMap;import java.util.Map;public class TestMapMerge { public static void main(String[] args) { Mapmap1=new HashMap (); Map map2=new HashMap (); map1.put("a", "Hello"); map2.put("b", "world"); map1.putAll(map2); System.out.println(map1.get("a")+(String)map2.get("b")); }}
输出结果为:Helloworld