Concatenate byte Array - Java java.lang

Java examples for java.lang:byte Array

Description

Concatenate byte Array

Demo Code


//package com.java2s;

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

    @SuppressWarnings("unused")
    private static byte[] ConcatArray(byte[] array1, byte[] array2) {
        byte[] output = new byte[array1.length + array2.length];
        System.arraycopy(array1, 0, output, 0, array1.length);
        System.arraycopy(array2, 0, output, array1.length, array2.length);
        return output;
    }
}

Related Tutorials