Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> T[] collectionToArray(Collection<T> sourceCollection, Class<?> elementClass) {
        Object array = Array.newInstance(elementClass, sourceCollection.size());
        Iterator iterator = sourceCollection.iterator();
        for (int i = 0; i < sourceCollection.size(); i++) {
            Array.set(array, i, iterator.next());
        }
        return (T[]) array;
    }
}