Java tutorial
//package com.java2s; /* * Copyright 2011-2016 ZXC.com All right reserved. This software is the confidential and proprietary information of * ZXC.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into with ZXC.com. */ import java.util.Collection; import java.util.Enumeration; public class Main { @SuppressWarnings("unchecked") public static <T extends Collection<K>, K> T toCollection(Class<?> clazz, Enumeration<K> enumeration) { if (clazz == null) { throw new RuntimeException("Class cannot be null."); } try { T collection = (T) clazz.newInstance(); if (enumeration != null) { while (enumeration.hasMoreElements()) { collection.add(enumeration.nextElement()); } } return collection; } catch (Exception e) { throw new RuntimeException(e); } } }