java.util.Collections.checkedMap() 方法


java.util.Collections.checkedMap() 方法

package com.codingdict;

import java.util.*;

public class CollectionsDemo {
   public static void main(String args[]) {

      // create map     
      HashMap<String,String> hmap = new HashMap<String,String>();

      // populate the map
      hmap.put("1", "Always");
      hmap.put("2", "follow");
      hmap.put("3", "tutorials");
      hmap.put("4", "point");

      // get typesafe view of the map
      Map<String,String> tsmap;
      tsmap = Collections.checkedMap(hmap,String.class,String.class);     

      System.out.println("Dynamically typesafe view of the map: "+tsmap);
   }    
}