Skip to content

Instantly share code, notes, and snippets.

@suxiaogang
Created June 12, 2014 09:10
Show Gist options
  • Save suxiaogang/6622dc8bdb54cafa5908 to your computer and use it in GitHub Desktop.
Save suxiaogang/6622dc8bdb54cafa5908 to your computer and use it in GitHub Desktop.
concat arrays
/**
* 多个数组进行合并
*
* @author Sam Su
* @date 2013-07-12
* @param <T>
* @param first
* @param rest
* @return
*/
public static <T> T[] concatAll(T[] first, T[]... rest) {
int totalLength = first.length;
for (T[] array : rest) {
totalLength += array.length;
}
T[] result = Arrays.copyOf(first, totalLength);
int offset = first.length;
for (T[] array : rest) {
System.arraycopy(array, 0, result, offset, array.length);
offset += array.length;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment