java.util.Collections.checkedSortedMap() 方法


java.util.Collections.checkedSortedMap() 方法

package com.codingdict;

import java.util.*;

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

      // create sorted map    
      SortedMap<String,String> smap = new TreeMap<String,String>();

      // populate the map
      smap.put("1", "Only");
      smap.put("2", "tutorials");
      smap.put("3", "point");

      // get typesafe view of the sorted map
      SortedMap<String,String> tsmap;

      tsmap = Collections.checkedSortedMap(smap,String.class,String.class);

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