checkedCollection(Collection<E>, Class<E>)%uA0方法用于获取指定集合的一个动态类型安全视图。
声明
以下是java.util.Collections.checkedCollection()方法的声明。
public static <E> Collection<E> checkedCollection(Collection<E> c,Class<E> type)
参数
-
c--这对于一个动态类型安全视图是要返回的集合。
-
type--类型元素c允许保持。
返回值
在方法调用返回指定集合的一个动态类型安全视图。
异常
-
NA
例子
下面的例子显示java.util.Collections.checkedCollection()方法的使用
package com.yiibai import java.util.* public class CollectionsDemo { public static void main(String args[]) { // create arraylist ArrayList<String> arlst = new ArrayList<String>() // populate the list arlst.add("TP") arlst.add("PROVIDES") arlst.add("QUALITY") arlst.add("TUTORIALS") // create typesafe view of the collection Collection<String> tslst tslst = Collections.checkedCollection(arlst,String.class) System.out.println("Type safe view is: "+tslst) } }
Let us compile and run the above program, this will produce the following result.
Type safe view is: [TP, PROVIDES, QUALITY, TUTORIALS]