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.List;

public class Main {

    @SuppressWarnings("unchecked")
    public static <T> T[] listToArray(List<T> list) {
        if (list == null) {
            return null;
        }

        T[] tArr = (T[]) Array.newInstance(list.get(0).getClass(), list.size());
        return list.toArray(tArr);
    }
}