public static Object[] concatenate(T[] a, T[] b)
{
// Function to merge two arrays of
// same type
return Stream.of(a, b)
.flatMap(Stream::of)
.toArray();
// Arrays::stream can also be used in place
// of Stream::of in the flatMap() above.
}
public static void main (String[] args)
{
Integer[] a = new Integer[]{1,2,3};
Integer[] b = new Integer[]{4,5,6};
public static Object[] concatenate(T[] a, T[] b)
{
// Function to merge two arrays of
// same type
return Stream.concat(Arrays.stream(a),
Arrays.stream(b))
.toArray();
}
public static void main (String[] args)
{
Integer[] a = new Integer[]{1,2,3};
Integer[] b = new Integer[]{4,5,6};
System.arraycopy(): The java.lang.System.arraycopy() method copies a source array from a specific beginning position to the destination array from the mentioned position. No. of arguments to be copied are decided by len argument.
源位置到源位置+长度–1 的组件从目标位置到目标位置+长度–1 被复制到目标阵列。
类别申报:
```java
public final class System extends Object
```
语法:
```java
public static void arraycopy(Object source_arr, int sourcePos,
Object dest_arr, int destPos, int len)
Parameters :
source_arr : array to be copied from
sourcePos : starting position in source array from where to copy
dest_arr : array to be copied in
destPos : starting position in destination array, where to copy in
len : total no. of components to be copied.
// Function to merge two arrays of same type
public static Object[] concatenate(T[] a, T[] b)
{
// Create an empty Object array of the combined
// size of the array a and array b
Object[] n=new Object[a.length + b.length];
// Copy the array a into n
System.arraycopy(a, 0, n, 0, a.length);
// Copy the array b into n
System.arraycopy(b, 0, n, a.length, b.length);
return n;
}
public static void main (String[] args)
{
Integer[] a = new Integer[]{1,2,3};
Integer[] b = new Integer[]{4,5,6};