Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2012-2013, Linagora
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *       Linagora - initial API and implementation
 *******************************************************************************/

import java.lang.reflect.Array;
import java.util.Collection;

public class Main {
    /**
     * Converts a collection into an array.
     * @param collection the collection to convert
     * @param clazz the class of the items in the collections
     * @return a non-null array
     */
    public static <T> T[] convertToArray(Collection<T> collection, Class<T> clazz) {
        T[] result = (T[]) Array.newInstance(clazz, collection.size());
        return collection.toArray(result);
    }
}