java.util.WeakHashMap.putAll() 方法


java.util.WeakHashMap.putAll() 方法

package com.codingdict;

import java.util.Map;
import java.util.WeakHashMap;

public class WeakHashMapDemo {
   public static void main(String[] args) {
      Map<String, String> weakHashMapOne = new WeakHashMap<String, String>();
      Map<String, String> weakHashMapTwo = new WeakHashMap<String, String>();

      // put keys and values in the Map
      System.out.println("Populating two Maps");

      weakHashMapOne.put("1", "first");
      weakHashMapOne.put("2", "two");
      weakHashMapOne.put("3", "three");

      weakHashMapTwo.put("1", "1st");
      weakHashMapTwo.put("2", "2nd");
      weakHashMapTwo.put("3", "3rd");

      // checking Map
      System.out.println("Before - Map 1: "+weakHashMapOne);
      System.out.println("Before - Map 2: "+weakHashMapTwo);

      // putting map 2 into map1
      weakHashMapOne.putAll(weakHashMapTwo);

      System.out.println("After - Map 1: "+weakHashMapOne);
      System.out.println("After - Map 2: "+weakHashMapTwo);
   }     
}