checkedSet(Set<E>, Class<E>)%uA0方法用于获取指定集合的动态类型安全视图。
声明
以下是java.util.Collections.checkedSet()方法的声明。
public static <E> Set<E> checkedSet(Set<E> s, Class<E> type)
参数
-
s--这对于一个动态类型安全视图是要返回的集合。
-
type --这是元素s被允许保持的类型。
返回值
在方法调用返回指定set的一个动态类型安全视图。
异常
-
NA
例子
下面的例子显示java.util.Collections.checkedSet()方法的使用
package com.yiibai 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) } }
让我们来编译和运行上面的程序,这将产生以下结果。
Dynamically typesafe view of the set: [Collections, in, java]