Java Array to List toList(Boolean[] list)

Here you can find the source of toList(Boolean[] list)

Description

to List

License

Open Source License

Declaration

public static List<Boolean> toList(Boolean[] list) 

Method Source Code

//package com.java2s;
/**//from  w  w  w  .  j av a 2s. c  om
 * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

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

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

        for (Boolean value : list) {
            newList.add(value);
        }

        return newList;
    }

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

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

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

        return newList;
    }

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

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

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

        return newList;
    }

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

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

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

        return newList;
    }

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

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

        for (Long value : list) {
            newList.add(value);
        }

        return newList;
    }

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

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

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

        return newList;
    }

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

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

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

        return newList;
    }
}

Related

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