Java examples for java.util:List Element
An easy way to construct an array list from Elements.
//package com.java2s; import java.util.ArrayList; public class Main { /**/*from w w w. j a v a 2s .co m*/ * An easy way to construct an array list. just do * * <pre> * ArrayList<String> al = CollectionHelper.ArrayList("a", "b", "c"); * </pre> * * Rather than * * <pre> * ArrayList<String> al = new ArrayList<String>() * al.add("a"); * al.add("b"); * al.add("c"); * </pre> * * @param elements * the elements to create an ArrayList of * @return a freshly created <tt>ArrayList</tt> containing elements given as arguments. If elements is null, null * is returned. * @since 0.1 */ public static <T> ArrayList<T> arrayList(final T... elements) { if (elements == null) return null; final ArrayList<T> result = new ArrayList<T>(elements.length); for (final T elem : elements) { result.add(elem); } return result; } }