java.util.Collections.checkedSortedSet() 方法


java.util.Collections.checkedSortedSet() 方法

package com.codingdict;

import java.util.*;

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

      // create sorted set    
      SortedSet<String> sset = new TreeSet<String>();

      // populate the set
      sset.add("Java");
      sset.add("is");
      sset.add("best");

      // get typesafe view of the sorted set
      SortedSet<String> tsset;
      tsset = Collections.checkedSortedSet(sset,String.class);     

      System.out.println("Dynamically typesafe view: "+tsset);
   }    
}