java.util.Collections.checkedSet() 方法


java.util.Collections.checkedSet() 方法

package com.codingdict;

import java.util.*;

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

      // create set    
      TreeSet<String> hset = new TreeSet<String>();

      // populate the set
      hset.add("Collections");
      hset.add("in");
      hset.add("java");

      // get typesafe view of the set
      Set<String> tsset = Collections.checkedSet(hset,String.class);     

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