gpt4 book ai didi

java - 系统copyarray无法应用于对象--> int[]?

转载 作者:行者123 更新时间:2023-12-02 02:42:57 25 4
gpt4 key购买 nike

我正在尝试:

private int[] data = new int[1];
int[] newArr = new int[1];
System.arraycopy(data, 0, newArr, data.length);

但我得到:

error: method arraycopy in class System cannot be applied to given types;
System.arraycopy(data, 0, newArr, data.length);
^
required: Object,int,Object,int,int
found: int[],int,int[],int
reason: actual and formal argument lists differ in length
1 error

Compilation Failed

我确定可以复制 int[] 我做错的任何事情吗?

最佳答案

您只是缺少该方法的最后一个参数 here's javadoc 中关于参数的说法是这样的:

src - the source array.

srcPos - starting position in the source array.

dest - the destination array.

destPos - starting position in the destination data.

length - the number of array elements to be copied.

下面应该有效:

int[] data = new int[1];
int[] newArr = new int[1];
System.arraycopy(data, 0, newArr, 0, data.length);
System.out.println(Arrays.toString(newArr));

关于java - 系统copyarray无法应用于对象--> int[]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45116691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com