Java Integer Create toIntArray(boolean[] array)

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

Description

Coverts given booleans array to array of ints.

License

Open Source License

Parameter

Parameter Description
array booleans array to convert.

Return

converted array of ints.

Declaration

public static int[] toIntArray(boolean[] array) 

Method Source Code

//package com.java2s;
/*/*from   w  ww. ja va 2 s .  co m*/
 * The MIT License (MIT)
 *
 * Copyright (c) 2016. Diorite (by Bart?omiej Mazur (aka GotoFinal))
 *
 * 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.
 */

public class Main {
    /**
     * Coverts given booleans array to array of ints.
     *
     * @param array
     *         booleans array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(boolean[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i] ? 1 : 0;
        }
        return result;
    }

    /**
     * Coverts given shorts array to array of ints.
     *
     * @param array
     *         shorts array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(short[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (int) array[i];
        }
        return result;
    }

    /**
     * Coverts given chars array to array of ints.
     *
     * @param array
     *         chars array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(char[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (int) array[i];
        }
        return result;
    }

    /**
     * Coverts given bytes array to array of ints.
     *
     * @param array
     *         bytes array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(byte[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (int) array[i];
        }
        return result;
    }

    /**
     * Coverts given longs array to array of ints.
     *
     * @param array
     *         longs array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(long[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (int) array[i];
        }
        return result;
    }

    /**
     * Coverts given floats array to array of ints.
     *
     * @param array
     *         floats array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(float[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (int) array[i];
        }
        return result;
    }

    /**
     * Coverts given doubles array to array of ints.
     *
     * @param array
     *         doubles array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(double[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = (int) array[i];
        }
        return result;
    }

    /**
     * Coverts given ints array to array of ints.
     *
     * @param array
     *         ints array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(Integer[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i];
        }
        return result;
    }

    /**
     * Coverts given numbers array to array of bytes.
     *
     * @param array
     *         numbers array to convert.
     *
     * @return converted array of bytes.
     */
    public static int[] toIntArray(Number[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].intValue();
        }
        return result;
    }

    /**
     * Coverts given booleans array to array of ints.
     *
     * @param array
     *         booleans array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(Boolean[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i] ? 1 : 0;
        }
        return result;
    }

    /**
     * Coverts given shorts array to array of ints.
     *
     * @param array
     *         shorts array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(Short[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].intValue();
        }
        return result;
    }

    /**
     * Coverts given chars array to array of ints.
     *
     * @param array
     *         chars array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(Character[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            //noinspection UnnecessaryUnboxing
            result[i] = ((int) array[i].charValue());
        }
        return result;
    }

    /**
     * Coverts given bytes array to array of ints.
     *
     * @param array
     *         bytes array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(Byte[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].intValue();
        }
        return result;
    }

    /**
     * Coverts given longs array to array of ints.
     *
     * @param array
     *         longs array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(Long[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].intValue();
        }
        return result;
    }

    /**
     * Coverts given floats array to array of ints.
     *
     * @param array
     *         floats array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(Float[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].intValue();
        }
        return result;
    }

    /**
     * Coverts given doubles array to array of ints.
     *
     * @param array
     *         doubles array to convert.
     *
     * @return converted array of ints.
     */
    public static int[] toIntArray(Double[] array) {
        int[] result = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i].intValue();
        }
        return result;
    }
}

Related

  1. toInt32(long x)
  2. toInt32(Object prmIntObject)
  3. toInt4Trim(String value, int _default)
  4. toIntA(byte[] data)
  5. toIntArr(String s, String split)
  6. toIntArray(boolean[] selectedValues)
  7. toIntArray(byte[] byteArray)
  8. toIntArray(byte[] bytes)
  9. toIntArray(byte[] data)