将数组插入另一个数组 [英] Insert array into another array
本文介绍了将数组插入另一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一种写方法,用于将a []插入数字[]中存储在变量 location中的位置。
Writing method to insert a[] into numbers[] at a position stored in variable "location".
public boolean insertArray(int location, double a[])
{
if (length != MAX_CAPACITY)
{
numbers[location] = a[];
length++;
return true;
}
return false;
}
是否可以通过数组?
推荐答案
您可以使用 System.arraycopy
:
You can use System.arraycopy
:
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
这里是一个简单的示例,您可以按照以下示例来解决问题:
Here is a simple example you can follow to solve your problem :
double a[] = {1, 2, 3, 4, 5};
double b[] = {6, 7, 8};
int local = 5;
double result[] = new double[a.length + b.length];
System.arraycopy(a, 0, result, 0, a.length);
System.arraycopy(b, 0, result, local, b.length);
System.out.println(Arrays.toString(result));
输出
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
这篇关于将数组插入另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文