Java Array Concatenate concat(byte[] first, byte[] second)

Here you can find the source of concat(byte[] first, byte[] second)

Description

concat

License

Open Source License

Declaration

public static byte[] concat(byte[] first, byte[] second) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    public static byte[] concat(byte[] first, byte[] second) {
        if (first == null) {
            if (second == null) {
                return null;
            }//  ww  w. ja  va  2s . c  o m
            return second;
        }
        if (second == null) {
            return first;
        }

        byte[] result = Arrays.copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    }

    public static int[] concat(int[] first, int[] second) {
        if (first == null) {
            if (second == null) {
                return null;
            }
            return second;
        }
        if (second == null) {
            return first;
        }

        int[] result = Arrays.copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    }

    public static long[] concat(long[] first, long[] second) {
        if (first == null) {
            if (second == null) {
                return null;
            }
            return second;
        }
        if (second == null) {
            return first;
        }

        long[] result = Arrays.copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    }

    public static <T> T[] concat(T[] first, T[] second) {
        if (first == null) {
            if (second == null) {
                return null;
            }
            return second;
        }
        if (second == null) {
            return first;
        }

        T[] result = Arrays.copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    }
}

Related

  1. arrayConcatInt(final int[] original, final int[] appender)
  2. concat(boolean[] a, boolean[] b)
  3. concat(boolean[]... arys)
  4. concat(byte[] a, byte[]... b)
  5. concat(byte[] first, byte[] second)
  6. concat(byte[]... arrays)
  7. concat(double[] first, double[] second)
  8. concat(final T[] elements, final T... elementsToAppend)
  9. concat(final T[] first, final T[] second)