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;
/*//from   ww  w .  j  ava  2  s. c o  m
 * Copyright (C) 2012  Krawler Information Systems Pvt Ltd
 * All rights reserved.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

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

        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 Collections.EMPTY_LIST;
        }

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

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

        return list;
    }

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

        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 Collections.EMPTY_LIST;
        }

        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 Collections.EMPTY_LIST;
        }

        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 Collections.EMPTY_LIST;
        }

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

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

        return list;
    }

    public static List<Boolean> toList(Boolean[] array) {
        if ((array == null) || (array.length == 0)) {
            return Collections.EMPTY_LIST;
        }

        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 Collections.EMPTY_LIST;
        }

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

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

        return list;
    }

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

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

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

        return list;
    }

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

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

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

        return list;
    }

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

        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 Collections.EMPTY_LIST;
        }

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

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

        return list;
    }

    public static List<String> toList(String[] array) {
        if ((array == null) || (array.length == 0)) {
            return Collections.EMPTY_LIST;
        }

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

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

        return list;
    }
}

Related

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