Does collections type conversion util methods already exist in any API?
- by Delta
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?