This method converts a Boolean array to a primitive one - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

This method converts a Boolean array to a primitive one

Demo Code


//package com.java2s;

public class Main {
    /**/*from  ww w  .j a  va2s.c  o  m*/
     * This method converts a Boolean array to a primitive one
     *
     * @param array of the complex type Boolean
     * @return array of the primitive type
     */
    public static boolean[] toPrimitive(Boolean[] array) {

        boolean[] primitiveArray = new boolean[array.length];

        for (int i = 0; i < array.length; i++) {
            primitiveArray[i] = array[i];
        }

        return primitiveArray;
    }

    /**
     * This method converts a Byte array to a primitive one
     *
     * @param array of the complex type Byte
     * @return array of the primitive type
     */
    public static byte[] toPrimitive(Byte[] array) {

        byte[] primitiveArray = new byte[array.length];

        for (int i = 0; i < array.length; i++) {
            primitiveArray[i] = array[i];
        }

        return primitiveArray;
    }

    /**
     * This method converts a Short array to a primitive one
     *
     * @param array of the complex type Short
     * @return array of the primitive type
     */
    public static short[] toPrimitive(Short[] array) {

        short[] primitiveArray = new short[array.length];

        for (int i = 0; i < array.length; i++) {
            primitiveArray[i] = array[i];
        }

        return primitiveArray;
    }

    /**
     * This method converts an Integer array to a primitive one
     *
     * @param array of the complex type Integer
     * @return array of the primitive type
     */
    public static int[] toPrimitive(Integer[] array) {

        int[] primitiveArray = new int[array.length];

        for (int i = 0; i < array.length; i++) {
            primitiveArray[i] = array[i];
        }

        return primitiveArray;
    }

    /**
     * This method converts a Long array to a primitive one
     *
     * @param array of the complex type Long
     * @return array of the primitive type
     */
    public static long[] toPrimitive(Long[] array) {

        long[] primitiveArray = new long[array.length];

        for (int i = 0; i < array.length; i++) {
            primitiveArray[i] = array[i];
        }

        return primitiveArray;
    }

    /**
     * This method converts a Float array to a primitive one
     *
     * @param array of the complex type Float
     * @return array of the primitive type
     */
    public static float[] toPrimitive(Float[] array) {

        float[] primitiveArray = new float[array.length];

        for (int i = 0; i < array.length; i++) {
            primitiveArray[i] = array[i];
        }

        return primitiveArray;
    }

    /**
     * This method converts a Double array to a primitive one
     *
     * @param array of the complex type Double
     * @return array of the primitive type
     */
    public static double[] toPrimitive(Double[] array) {

        double[] primitiveArray = new double[array.length];

        for (int i = 0; i < array.length; i++) {
            primitiveArray[i] = array[i];
        }

        return primitiveArray;
    }
}

Related Tutorials