package test;
import java.util.LinkedHashMap;
import java.util.Map;
public class test {
public static void main(String[] args) {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map2 = new LinkedHashMap<String, String>();
map.put("1", "a");
map.put("2", "b");
map.put("3", "c");
map.put("3", "3");
map.put("4", "4");
map.put("5", "5");
map.putAll(map2);
System.out.println(map);
}
}
输出:
{1=a, 2=b, 3=3, 4=4, 5=5}
后面的map会覆盖前一个map中key相同的元素