Java Array to List toList(final int[] array)

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

Description

Convert an array of int to a list of Integers

License

GNU General Public License

Parameter

Parameter Description
array Array to convert

Return

a new list of integers

Declaration

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

Method Source Code

//package com.java2s;
/*/*from www.j  av  a2  s . c  o  m*/
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the ?cole Normale Sup?rieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Convert an array of int to a list of Integers
     * @param array Array to convert
     * @return a new list of integers
     */
    public static List<Integer> toList(final int[] array) {

        if (array == null)
            return null;

        final ArrayList<Integer> result = new ArrayList<Integer>(
                array.length);

        for (int i = 0; i < array.length; i++)
            result.add(Integer.valueOf(array[i]));

        return result;
    }

    /**
     * Convert an array of double to a list of Double
     * @param array Array to convert
     * @return a new list of Doubles
     */
    public static List<Double> toList(final double[] array) {

        if (array == null)
            return null;

        final ArrayList<Double> result = new ArrayList<Double>(array.length);

        for (int i = 0; i < array.length; i++)
            result.add(Double.valueOf(array[i]));

        return result;
    }

    /**
     * Convert an array of booleans to a list of Booleans
     * @param array Array to convert
     * @return a new list of Booleans
     */
    public static List<Boolean> toList(final boolean[] array) {

        if (array == null)
            return null;

        final ArrayList<Boolean> result = new ArrayList<Boolean>(
                array.length);

        for (int i = 0; i < array.length; i++)
            result.add(Boolean.valueOf(array[i]));

        return result;
    }
}

Related

  1. toList(E[] array, int fromIndex, int toIndex)
  2. toList(final double[] array)
  3. toList(final E[] array)
  4. toList(final float[] array)
  5. toList(final int[] array)
  6. ToList(final Object[] array)
  7. toList(final Object[] objects)
  8. toList(final T... objects)
  9. toList(final T[] array)