Java tutorial
//package com.java2s; /* * jPOS Project [http://jpos.org] * Copyright (C) 2000-2012 Alejandro P. Revilla * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Concatenates two byte arrays (array1 and array2) * @param array1 * @param array2 * @return the concatenated array */ public static byte[] concat(byte[] array1, byte[] array2) { byte[] concatArray = new byte[array1.length + array2.length]; System.arraycopy(array1, 0, concatArray, 0, array1.length); System.arraycopy(array2, 0, concatArray, array1.length, array2.length); return concatArray; } /** * Concatenates two byte arrays (array1 and array2) * @param array1 * @param beginIndex1 * @param length1 * @param array2 * @param beginIndex2 * @param length2 * @return the concatenated array */ public static byte[] concat(byte[] array1, int beginIndex1, int length1, byte[] array2, int beginIndex2, int length2) { byte[] concatArray = new byte[length1 + length2]; System.arraycopy(array1, beginIndex1, concatArray, 0, length1); System.arraycopy(array2, beginIndex2, concatArray, length1, length2); return concatArray; } }