Does collections type conversion util methods already exist in any API?

Posted by Delta on Stack Overflow See other posts from Stack Overflow or by Delta
Published on 2012-10-17T16:42:06Z Indexed on 2012/10/17 17:01 UTC
Read the original article Hit count: 241

Filed under:
|
|
interface TypeConverter<T, E> {
     T convert(E e);
}
class CollectionUtil() {
     public static <E> List<T> convertToList(List<E> fromList, TypeConverter<T, E> conv) {
     {
            if(fromList== null) return null;
            List<T> newList = new ArrayList<T>(fromList.size())  
            for(E e : fromList) 
            {
                newList.add(conv.convert(e));
            }
            return newList;
     } 
}

Above code explains converting from List of String to List of Integer by implementing TypeConverter interface for String, Integer. Are there already any collections conversion utility methods exists in any API like list to set and so on?

© Stack Overflow or respective owner

Related posts about java

Related posts about generics