Java Array to List toList(T... objects)

Here you can find the source of toList(T... objects)

Description

Converts the given objects into a List .

License

Open Source License

Parameter

Parameter Description
T The type of the objects.
objects The objects array to convert.

Return

The created .

Declaration

public static <T> List<T> toList(T... objects) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany
 *                    Technical University Darmstadt, Germany
 *                    Chalmers University of Technology, Sweden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w w w  .j a  v a  2  s.  c  om*/
 *    Technical University Darmstadt - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Converts the given objects into a {@link List}.
     * @param <T> The type of the objects.
     * @param objects The objects array to convert.
     * @return The created {@link List}.
     */
    public static <T> List<T> toList(T... objects) {
        if (objects != null) {
            List<T> result = new ArrayList<T>(objects.length);
            for (T obj : objects) {
                result.add(obj);
            }
            return result;
        } else {
            return new ArrayList<T>(0);
        }
    }
}

Related

  1. toList(T element, T... elements)
  2. toList(T value)
  3. toList(T... elements)
  4. toList(T... items)
  5. toList(T... objects)
  6. toList(T[] _array)
  7. toList(T[] anArrayToConvert)
  8. toList(T[] arr)
  9. toList(T[] array)