优化 concat 方法的实现。

feature/net-util
ZhouXY108 2023-06-26 09:10:16 +08:00
parent 9d9f9a34e1
commit 59f5a1d17b
1 changed files with 10 additions and 15 deletions

View File

@ -36,9 +36,8 @@ public class MoreArrays {
float[] result = new float[length]; float[] result = new float[length];
int i = 0; int i = 0;
for (float[] arr : arrays) { for (float[] arr : arrays) {
for (float item : arr) { System.arraycopy(arr, 0, result, i, arr.length);
result[i++] = item; i = arr.length;
}
} }
return result; return result;
} }
@ -51,9 +50,8 @@ public class MoreArrays {
double[] result = new double[length]; double[] result = new double[length];
int i = 0; int i = 0;
for (double[] arr : arrays) { for (double[] arr : arrays) {
for (double item : arr) { System.arraycopy(arr, 0, result, i, arr.length);
result[i++] = item; i = arr.length;
}
} }
return result; return result;
} }
@ -66,9 +64,8 @@ public class MoreArrays {
byte[] result = new byte[length]; byte[] result = new byte[length];
int i = 0; int i = 0;
for (byte[] arr : arrays) { for (byte[] arr : arrays) {
for (byte item : arr) { System.arraycopy(arr, 0, result, i, arr.length);
result[i++] = item; i = arr.length;
}
} }
return result; return result;
} }
@ -81,9 +78,8 @@ public class MoreArrays {
long[] result = new long[length]; long[] result = new long[length];
int i = 0; int i = 0;
for (long[] arr : arrays) { for (long[] arr : arrays) {
for (long item : arr) { System.arraycopy(arr, 0, result, i, arr.length);
result[i++] = item; i = arr.length;
}
} }
return result; return result;
} }
@ -96,9 +92,8 @@ public class MoreArrays {
int[] result = new int[length]; int[] result = new int[length];
int i = 0; int i = 0;
for (int[] arr : arrays) { for (int[] arr : arrays) {
for (int item : arr) { System.arraycopy(arr, 0, result, i, arr.length);
result[i++] = item; i = arr.length;
}
} }
return result; return result;
} }