Java List from Array asList(final T[] input)

Here you can find the source of asList(final T[] input)

Description

Return an ArrayList.

License

LGPL

Parameter

Parameter Description
input a parameter

Declaration

public static final <T> List<T> asList(final T[] input) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*w  ww .  j a va2  s.c o m*/
     * Return an ArrayList.
     * @param input
     * @return
     */
    public static final <T> List<T> asList(final T[] input) {
        final List<T> out = new ArrayList<T>(input.length);
        for (int i = 0; i < input.length; i++) {
            out.add(input[i]);
        }
        return out;
    }

    /**
     * Return an ArrayList.
     * @param input
     * @return
     */
    public static final List<Integer> asList(final int[] input) {
        final List<Integer> out = new ArrayList<Integer>(input.length);
        for (int i = 0; i < input.length; i++) {
            out.add(input[i]);
        }
        return out;
    }

    /**
     * Return an ArrayList.
     * @param input
     * @return
     */
    public static final List<Long> asList(final long[] input) {
        final List<Long> out = new ArrayList<Long>(input.length);
        for (int i = 0; i < input.length; i++) {
            out.add(input[i]);
        }
        return out;
    }

    /**
     * Return an ArrayList.
     * @param input
     * @return
     */
    public static final List<Double> asList(final double[] input) {
        final List<Double> out = new ArrayList<Double>(input.length);
        for (int i = 0; i < input.length; i++) {
            out.add(input[i]);
        }
        return out;
    }

    /**
     * Return an ArrayList.
     * @param input
     * @return
     */
    public static final List<Float> asList(final float[] input) {
        final List<Float> out = new ArrayList<Float>(input.length);
        for (int i = 0; i < input.length; i++) {
            out.add(input[i]);
        }
        return out;
    }

    /**
     * Return an ArrayList.
     * @param input
     * @return
     */
    public static final List<Boolean> asList(final boolean[] input) {
        final List<Boolean> out = new ArrayList<Boolean>(input.length);
        for (int i = 0; i < input.length; i++) {
            out.add(input[i]);
        }
        return out;
    }
}

Related

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