Java Array to List toList(int[] array)

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

Description

Converts the given array of integers to a list of instances of class Integer

License

Open Source License

Parameter

Parameter Description
array the array

Return

the list of instances of class Integer representing the original array

Declaration

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

Method Source Code


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

import java.util.*;

public class Main {
    /**/*  w w  w.jav a 2s .c  o  m*/
     * Converts the given array of integers to a list of instances of class Integer
     * @param array the array
     * @return the list of instances of class Integer representing the original array
     */
    public static List<Integer> toList(int[] array) {
        List<Integer> list = new ArrayList<Integer>();
        for (int i : array) {
            list.add(i);
        }
        return list;
    }

    /**
     * Converts the given array of doubles to a list of instances of class Double
     * @param array the array
     * @return the list of instances of class Double representing the original array
     */
    public static List<Double> toList(double[] array) {
        List<Double> list = new ArrayList<Double>();
        for (double i : array) {
            list.add(i);
        }
        return list;
    }

    /**
     * Converts the given array of booleans to a list of instances of class Boolean
     * @param array the array
     * @return the list of instances of class Boolean representing the original array
     */
    public static List<Boolean> toList(boolean[] array) {
        List<Boolean> list = new ArrayList<Boolean>();
        for (boolean i : array) {
            list.add(i);
        }
        return list;
    }
}

Related

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