This function converts an array of type int into an array of type byte - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

This function converts an array of type int into an array of type byte

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int[] in = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(java.util.Arrays.toString(convertIntArray(in)));
    }/*from   w ww  .j  a  va  2 s .c o m*/

    /**
     * This function converts an array of type int into an array of type byte
     * 
     * @param in
     *            the array to be converted
     * @return out the byte-array that corresponds the input
     */
    public static byte[] convertIntArray(int[] in) {
        byte[] out = new byte[in.length];
        for (int i = 0; i < in.length; i++) {
            out[i] = (byte) in[i];
        }
        return out;
    }
}

Related Tutorials