Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { /** * * @param elements * @return */ public static <E> List<E> asList(E... elements) { if (elements == null || elements.length == 0) { return Collections.emptyList(); } // Avoid integer overflow when a large array is passed in int capacity = computeListCapacity(elements.length); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; } static int computeListCapacity(int arraySize) { return (int) Math.min(5L + arraySize + (arraySize / 10), Integer.MAX_VALUE); } }