目录

void putAll(Map<? extends K,? extends V> m)

描述 (Description)

putAll(Map《? extends K,? extends V》 t)方法用于将指定映射中的所有映射复制到此映射。

声明 (Declaration)

以下是java.util.IdentityHashMap.putAll()方法的声明。

public void putAll(Map<? extends K,? extends V> t)

参数 (Parameters)

t - 这是要存储在此映射中的映射。

返回值 (Return Value)

方法调用返回与key关联的先前值,如果没有key的映射,则返回null。

异常 (Exception)

NullPointerException - 如果指定的映射为null,则抛出此异常。

例子 (Example)

以下示例显示了java.util.IdentityHashMap.putAll()的用法

package com.iowiki;
import java.util.*;
public class IdentityHashMapDemo {
   public static void main(String args[]) {
      // create 2 identity hash maps
      IdentityHashMap ihmap1 = new IdentityHashMap();
      IdentityHashMap ihmap2 = new IdentityHashMap();
      // populate the ihmap1
      ihmap1.put(1, "java");
      ihmap1.put(2, "util");
      ihmap1.put(3, "package");
      System.out.println("Value of ihmap1 before: " + ihmap1);
      System.out.println("Value of ihmap2 before: " + ihmap2);
      // put all values from ihmap1 to ihmap2
      ihmap2.putAll(ihmap1);
      System.out.println("Value of ihmap2 after: " + ihmap2);
   }    
}

让我们编译并运行上面的程序,这将产生以下结果。

Value of ihmap1 before: {2=util, 3=package, 1=java}
Value of ihmap2 before: {}
Value of ihmap2 after: {2=util, 3=package, 1=java}
↑回到顶部↑
WIKI教程 @2018