Java Array to List toList(int[] from)

Here you can find the source of toList(int[] from)

Description

Creates a new ArrayList from the given Array (by copying).

License

Open Source License

Parameter

Parameter Description
from the Array to create the list from.

Return

a new ArrayList containing all elements in the given Array.

Declaration

public static ArrayList<Integer> toList(int[] from) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    /**/*  www  .  j  a  v  a 2  s.c  o  m*/
     * Creates a new ArrayList from the given Array (by copying).
     *
     * @param from the Array to create the list from.
     * @return a new ArrayList containing all elements in the given Array.
     */
    public static ArrayList<Integer> toList(int[] from) {
        ArrayList<Integer> list = new ArrayList<>(from.length);

        for (int i : from)
            list.add(i);

        return list;
    }

    /**
     * Creates a new ArrayList from the given Array (by copying).
     *
     * @param from the Array to create the list from.
     * @return a new ArrayList containing all elements in the given Array.
     */
    public static ArrayList<Long> toList(long[] from) {
        ArrayList<Long> list = new ArrayList<>(from.length);

        for (long l : from)
            list.add(l);

        return list;
    }
}

Related

  1. toList(final T[] array)
  2. toList(int[] a)
  3. toList(int[] arr)
  4. toList(int[] array)
  5. toList(int[] array)
  6. toList(Object[] arr)
  7. toList(Object[] array)
  8. toList(Object[] array)
  9. toList(Object[] array)