void putAll(Map<? extends K,? extends V> m)
描述 (Description)
putAll(Map《? extends K,? extends V》 m)方法用于将指定映射中的所有映射复制到此映射。
声明 (Declaration)
以下是java.util.HashMap.putAll()方法的声明。
public void putAll(Map<? extends K,? extends V> m)
参数 (Parameters)
m - 这是存储在此映射中的映射。
返回值 (Return Value)
NA
异常 (Exception)
NullPointerException - 如果指定的映射为null,则抛出此异常。
例子 (Example)
以下示例显示了java.util.HashMap.putAll()的用法
package com.iowiki;
import java.util.*;
public class HashMapDemo {
public static void main(String args[]) {
// create two hash maps
HashMap newmap1 = new HashMap();
HashMap newmap2 = new HashMap();
// populate hash map
newmap1.put(1, "tutorials");
newmap1.put(2, "point");
newmap1.put(3, "is best");
System.out.println("Values in newmap1: "+ newmap1);
// put all values in newmap2
newmap2.putAll(newmap1);
System.out.println("Values in newmap2: "+ newmap2);
}
}
让我们编译并运行上面的程序,这将产生以下结果。
Values in newmap1: {1=tutorials, 2=point, 3=is best}
Values in newmap2: {1=tutorials, 2=point, 3=is best}