concatenate two byte array - Java java.lang

Java examples for java.lang:byte Array

Description

concatenate two byte array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] bytes1 = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        byte[] bytes2 = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(java.util.Arrays
                .toString(concat(bytes1, bytes2)));
    }/* www .  j  ava  2s.co m*/

    private static byte[] concat(byte[] bytes1, byte[] bytes2) {
        byte[] big = new byte[bytes1.length + bytes2.length];
        System.arraycopy(bytes1, 0, big, 0, bytes1.length);
        System.arraycopy(bytes2, 0, big, bytes1.length, bytes2.length);
        return big;
    }
}

Related Tutorials