集册 Java实例教程 此函数将int类型的数组转换为byte类型的数组

此函数将int类型的数组转换为byte类型的数组

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

317
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
此函数将int类型的数组转换为byte类型的数组


//package com.nowjava;
/**时 代 J a v a - N o w J a v a . c o m**/

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

    }


    /**

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

        
展开阅读全文