Java Array to List toList(boolean[] array)

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

Description

to List

License

Open Source License

Declaration

public static List<Boolean> toList(boolean[] array) 

Method Source Code

//package com.java2s;
/**/*w ww.ja  va2  s.c o  m*/
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class Main {
    public static List<Boolean> toList(boolean[] array) {
        if ((array == null) || (array.length == 0)) {
            return new ArrayList<Boolean>();
        }

        List<Boolean> list = new ArrayList<Boolean>(array.length);

        for (boolean value : array) {
            list.add(value);
        }

        return list;
    }

    public static List<Double> toList(double[] array) {
        if ((array == null) || (array.length == 0)) {
            return new ArrayList<Double>();
        }

        List<Double> list = new ArrayList<Double>(array.length);

        for (double value : array) {
            list.add(value);
        }

        return list;
    }

    public static <E> List<E> toList(E[] array) {
        if ((array == null) || (array.length == 0)) {
            return new ArrayList<E>();
        }

        return new ArrayList<E>(Arrays.asList(array));
    }

    public static List<Float> toList(float[] array) {
        if ((array == null) || (array.length == 0)) {
            return new ArrayList<Float>();
        }

        List<Float> list = new ArrayList<Float>(array.length);

        for (float value : array) {
            list.add(value);
        }

        return list;
    }

    public static List<Integer> toList(int[] array) {
        if ((array == null) || (array.length == 0)) {
            return new ArrayList<Integer>();
        }

        List<Integer> list = new ArrayList<Integer>(array.length);

        for (int value : array) {
            list.add(value);
        }

        return list;
    }

    public static List<Long> toList(long[] array) {
        if ((array == null) || (array.length == 0)) {
            return new ArrayList<Long>();
        }

        List<Long> list = new ArrayList<Long>(array.length);

        for (long value : array) {
            list.add(value);
        }

        return list;
    }

    public static List<Short> toList(short[] array) {
        if ((array == null) || (array.length == 0)) {
            return new ArrayList<Short>();
        }

        List<Short> list = new ArrayList<Short>(array.length);

        for (short value : array) {
            list.add(value);
        }

        return list;
    }
}

Related

  1. newList(T... ts)
  2. newList(T... values)
  3. newList(V... items)
  4. toList(@SuppressWarnings("unchecked") T... ts)
  5. toList(boolean... booleans)
  6. toList(boolean[] array)
  7. toList(Boolean[] list)
  8. toList(byte[] array)
  9. toList(byte[] array)