集册 Java实例教程 此方法将布尔数组转换为基元数组

此方法将布尔数组转换为基元数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

237
此方法将布尔数组转换为基元数组


//package com.nowjava;


public class Main {
/** 
来 自 
nowjava.com
**/

    /**

     * 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];

        }
        /* from 
        n o w    j a v a  . c o m*/


        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];

        }

展开阅读全文