Here you can find the source of convertCollectionType(Iterable> from, C newCollection, Class
public static <T, C extends Collection<T>> C convertCollectionType(Iterable<?> from, C newCollection, Class<T> listClass)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009-2018 Weasis Team and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html * * Contributors://from ww w .j a va 2 s. c o m * Nicolas Roduit - initial API and implementation *******************************************************************************/ import java.util.Collection; public class Main { public static <T, C extends Collection<T>> C convertCollectionType(Iterable<?> from, C newCollection, Class<T> listClass) { for (Object item : from) { newCollection.add(listClass.cast(item)); } return newCollection; } }