Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.lang.reflect.Array;

import java.util.Collection;

public class Main {
    /**
     * Calls the {@link Collection#toArray(Object[])} method constructing array based on the given argument type.
     *
     * @param <E>
     *            the element type
     * @param collection
     *            the collection
     * @param type
     *            the type
     * @return the e[]
     */
    @SuppressWarnings("unchecked")
    public static <E> E[] toArray(Collection<? extends E> collection, Class<E> type) {
        return collection.toArray((E[]) Array.newInstance(type, collection.size()));
    }
}