Java Array to List toList(int[] arr)

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

Description

convert the int array to a list.

License

Apache License

Parameter

Parameter Description
arr the int array

Return

the result list.

Declaration

public static List<Integer> toList(int[] arr) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*w ww  . j av a2 s.c  o m*/
     * convert the int array to a list.
     * @param arr the int array
     * @return the result list.
     */
    public static List<Integer> toList(int[] arr) {
        return toList(arr, null);
    }

    /**
     * convert the int array to a list.
     * @param arr the int array
     * @param out the out list, can be null
     * @return the result list.
     */
    public static List<Integer> toList(int[] arr, List<Integer> out) {
        if (out == null) {
            out = new ArrayList<>();
        }
        for (int size = arr.length, i = 0; i < size; i++) {
            out.add(arr[i]);
        }
        return out;
    }
}

Related

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