generic method to concatenate two array - Android java.lang

Android examples for java.lang:array union merge

Description

generic method to concatenate two array

Demo Code

import java.util.Arrays;

public class Main {

  public static <T> T[] concat(T[] first, T[] second) {
    T[] result = Arrays.copyOf(first, first.length + second.length);
    System.arraycopy(second, 0, result, first.length, second.length);
    return result;
  }//from w  ww .j a  v a2  s . c  o  m

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

}

Related Tutorials