Java List from Array asList(E[] array)

Here you can find the source of asList(E[] array)

Description

Given an array of a particular type, it will return it as a List of the same type.

License

Open Source License

Parameter

Parameter Description
array a parameter

Return

<E> <E>

Declaration

public static <E> List<E> asList(E[] array) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**//  w w  w  .  ja  v a2  s  .  co m
     * <p>Given an array of a particular type, it will return it
     * as a List of the same type.</p>
     * 
     * @param &lt;E&gt;
     * @param array
     * @return &lt;E&gt; {@link List}&lt;E&gt;
     */
    public static <E> List<E> asList(E[] array) {
        List<E> list = new ArrayList<E>(array.length);
        for (int i = 0; i < array.length; i++) {
            list.add(array[i]);
        }

        return list;
    }
}

Related

  1. asList(Collection coll)
  2. asList(Collection collection)
  3. asList(double[] array)
  4. asList(E... elements)
  5. asList(E... pEntities)
  6. asList(final char[] array)
  7. asList(final Collection collection)
  8. asList(final Collection c)
  9. asList(final E... array)