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 {
    public static <T> T[] list2Array(List<T> list, Class<T> clazz) {
        if (list != null) {
            @SuppressWarnings("unchecked")
            T[] array = (T[]) Array.newInstance(clazz, list.size());
            for (int i = 0; i < list.size(); i++) {
                array[i] = list.get(i);
            }
            return array;
        }
        return null;
    }
}