copy Collection - Java Collection Framework

Java examples for Collection Framework:Collections Utility Methods

Description

copy Collection

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        Collection collection = java.util.Arrays.asList("asdf",
                "java2s.com");
        System.out.println(copy(collection));
    }/* w w  w .ja v  a2s  .  c  o  m*/

    public static <T> List<T> copy(Collection<T> collection) {
        @SuppressWarnings("unchecked")
        List<T> ret = (List<T>) provideListFor(Object.class);
        ret.addAll(collection);
        return ret;
    }

    public static <T> List<T> provideListFor(Class<T> c) {
        return new ArrayList<T>();
    }
}

Related Tutorials