Java examples for java.util:Collection Element
cast Collection element by class
//package com.java2s; import java.util.Collection; public class Main { public static void main(String[] argv) { Collection collection = java.util.Arrays.asList("asdf", "java2s.com"); Class clazz = String.class; System.out.println(cast(collection, clazz)); }//from ww w .j a v a 2 s . c o m public static <T> Collection<T> cast(Collection<? super T> collection, Class<T> clazz) { return (Collection<T>) collection; } }