09月09, 2019

java数组复制方法

apache-commons

ArrayUtils.addAll(Object[], Object[])

java

// Arrays.copyOf()
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;
}
// System.arraycopy()
static String[] concat(String[] a, String[] b) {
  String[] c= new String[a.length+b.length];
  System.arraycopy(a, 0, c, 0, a.length);
  System.arraycopy(b, 0, c, a.length, b.length);
  return c;
}

本文链接:https://blog.jnliok.com/post/java-ArrayCopy.html

-- EOF --

Comments