Java tutorial
//package com.java2s; /** * Copyright 2013-present febit.org (support@febit.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.lang.reflect.Array; import java.util.*; import java.util.function.IntFunction; public class Main { public static Object[] toArray(List list) { return list.toArray(); } @SuppressWarnings("unchecked") public static <T> T[] toArray(List<T> list, Class<T> componentType) { return list.toArray((T[]) Array.newInstance(componentType, list.size())); } public static <T> T[] toArray(Collection<T> list, IntFunction<T[]> action) { return list.toArray(action.apply(list.size())); } public static Object[] toArray(Object... args) { return args; } public static String[] toArray(String... args) { return args; } public static int[] toArray(int... args) { return args; } public static long[] toArray(long... args) { return args; } public static boolean[] toArray(boolean... args) { return args; } public static char[] toArray(char... args) { return args; } public static byte[] toArray(byte... args) { return args; } public static float[] toArray(float... args) { return args; } public static short[] toArray(short... args) { return args; } public static double[] toArray(double... args) { return args; } }