Java Collection Tutorial - Java WeakHashMap(Map <? extends K ,? extends V > m) Constructor


WeakHashMap(Map <? extends K ,? extends V > m) constructor from WeakHashMap has the following syntax.

public WeakHashMap(Map <? extends K ,? extends V> m)


In the following code shows how to use WeakHashMap.WeakHashMap(Map <? extends K ,? extends V > m) constructor.

import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
/*  w w  w  .ja  va  2 s . c o  m*/
public class Main {
   public static void main(String[] args) { 
      Map<String, String>  hashMap = new HashMap<String, String> ();
      hashMap.put("1", "first");
      hashMap.put("2", "two");
      hashMap.put("3", "from");
      Map<String, String>  weakHashMap = new WeakHashMap<String, String> (hashMap);