java.util.HashMap.clone() 方法


java.util.HashMap.clone() 方法

package com.codingdict;

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 1st map
      newmap1.put(1, "tutorials");
      newmap1.put(2, "point");
      newmap1.put(3, "is best");

      // clone 1st map
      newmap2 = (HashMap)newmap1.clone();

      System.out.println("1st Map: " + newmap1);
      System.out.println("Cloned 2nd Map: " + newmap2);   
   }    
}