Java Collection to Array toArray(Collection list)

Here you can find the source of toArray(Collection list)

Description

Converts a collection ( List , Set ...) of Boolean objects to a boolean[] .

License

Open Source License

Parameter

Parameter Description
list Input list

Return

boolean[]

Declaration

public static boolean[] toArray(Collection<Boolean> list) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 Pablo Pavon-Marino.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * Contributors:/*from w  ww  .j  a v  a2s.c o m*/
 *     Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1
 *     Pablo Pavon-Marino - from version 0.4.0 onwards
 ******************************************************************************/

import java.util.Collection;

public class Main {
    /**
     * Converts a collection ({@code List}, {@code Set}...) of {@code Boolean} objects to a {@code boolean[]}.
     *
     * @param list Input list
     * @return {@code boolean[]}
     */
    public static boolean[] toArray(Collection<Boolean> list) {
        return asPrimitiveArray(list.toArray(new Boolean[list.size()]));
    }

    /**
     * Converts from {@code Boolean[]} to {@code boolean[]}.
     *
     * @param array {@code Boolean[]}
     * @return Equivalent {@code boolean[]}
     */
    public static boolean[] asPrimitiveArray(Boolean[] array) {
        boolean[] primitiveArray = new boolean[array.length];
        for (int i = 0; i < array.length; i++)
            primitiveArray[i] = array[i];

        return primitiveArray;
    }
}

Related

  1. toArray(Collection coll)
  2. toArray(Collection bytes)
  3. toArray(Collection c, T[] arr)
  4. toArray(Collection collection)
  5. toArray(Collection tests)
  6. toArray(Collection values)
  7. toArray(Collection values)
  8. toArray(Collection collection)
  9. toArray(Collection collection)