java.util.Hashtable.putAll() 方法
描述
putAll(Map<? extends K,? extends V> t) 方法用于将指定 Map 中的所有映射复制到此 Hashtable。
声明
以下是 java.util.Hashtable.putAll() 方法的声明。
public void putAll(Map<? extends K,? extends V> t)
参数
t − 这是要存储在此映射中的映射。
返回值
NA
异常
NullPointerException − 如果指定的映射为 null,则抛出此错误。
示例
下面的例子展示了 java.util.Hashtable.putAll() 的用法。
package com.tutorialspoint;
import java.util.*;
public class HashTableDemo {
public static void main(String args[]) {
// create hash table
Hashtable htable1 = new Hashtable();
// create Map
Map map = new HashMap();
// put values in map
map.put("1","TP");
map.put("2","IS");
map.put("3","BEST");
System.out.println("Initial hash table value: "+htable1);
System.out.println("Map values: "+map);
// put map values in table
htable1.putAll(map);
System.out.println("Hash table value after put all: "+htable1);
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Initial hash table value: {}
Map values: {3=BEST, 2=IS, 1=TP}
Hash table value after put all: {3=BEST, 2=IS, 1=TP}

