Java List from Array asList(int... array)

Here you can find the source of asList(int... array)

Description

Returns a list given the argument array.

License

Open Source License

Parameter

Parameter Description
array The array.

Return

The list.

Declaration

public static List<Integer> asList(int... array) 

Method Source Code

//package com.java2s;
/*/*from  ww  w .  j  a  va 2  s .c o m*/
 * Copyright (C) 2015 Miquel Sas
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * Returns a list given the argument array.
     * 
     * @param array The array.
     * @return The list.
     */
    public static List<Integer> asList(int... array) {
        List<Integer> list = new ArrayList<>();
        for (int element : array) {
            list.add(element);
        }
        return list;
    }

    /**
     * Returns a list given the argument array.
     * 
     * @param array The array.
     * @return The list.
     */
    public static List<Double> asList(double... array) {
        List<Double> list = new ArrayList<>();
        for (double element : array) {
            list.add(element);
        }
        return list;
    }

    /**
     * Returns a list given the argument array.
     * 
     * @param <T> The type.
     * @param array The array.
     * @return The list.
     */
    @SafeVarargs
    public static <T> List<T> asList(T... array) {
        List<T> list = new ArrayList<>();
        for (T element : array) {
            list.add(element);
        }
        return list;
    }
}

Related

  1. asList(final T... data)
  2. asList(final T... data)
  3. asList(final T[] array)
  4. asList(final T[] input)
  5. asList(float[] elements)
  6. asList(int... data)
  7. asList(int... values)
  8. asList(int[] a)
  9. asList(int[] ai)