Java Array Append appendArray(final byte[] buffer1, final byte[] buffer2)

Here you can find the source of appendArray(final byte[] buffer1, final byte[] buffer2)

Description

Appends the second array to the first array.

License

Open Source License

Parameter

Parameter Description
buffer1 The first buffer.
buffer2 The second buffer.

Return

The new array.

Declaration

public static final byte[] appendArray(final byte[] buffer1, final byte[] buffer2) 

Method Source Code

//package com.java2s;
/**/*from  ww w.j a v  a 2s  .  c  o  m*/
 * (C) Copyright 2007, Deft Labs.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser 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 General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Appends the second array to the first array. The buffer1 object
     * is modified to include the buffer2 object.
     * @param buffer1 The first buffer.
     * @param buffer2 The second buffer.
     * @return The new array.
     */
    public static final byte[] appendArray(final byte[] buffer1, final byte[] buffer2) {
        final byte[] newBuffer = new byte[buffer1.length + buffer2.length];
        int pos = 0;
        System.arraycopy(buffer1, 0, newBuffer, pos, buffer1.length);
        pos += buffer1.length;
        System.arraycopy(buffer2, 0, newBuffer, pos, buffer2.length);
        return newBuffer;
    }
}

Related

  1. addToArray(final int[] array, int index, final String csvString, final String delim)
  2. addToArray(int[] a, int value)
  3. addToArray(String[] items, String str)
  4. appendArray(int[][] array, int[] staple)
  5. appendArray(Object[] arr, Object obj)
  6. appendArray(Object[] array1, Object[] array2)
  7. appendArray(String[] A, String... B)