Created
June 12, 2014 09:10
-
-
Save suxiaogang/6622dc8bdb54cafa5908 to your computer and use it in GitHub Desktop.
concat arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 多个数组进行合并 | |
* | |
* @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