[英]The method set(int, Int) in the type ArrayList<Int> is not applicable for the arguments (int, int) length cannot be resolved or is not a field
My code is showing:我的代码显示:
The method set(int, Int) in the type ArrayList is not applicable for the arguments (int, int) length cannot be resolved or is not a field
ArrayList 类型中的方法 set(int, Int) 不适用于 arguments (int, int) 长度无法解析或不是字段
but I don't know how to resolve it.但我不知道如何解决它。
package revision;
import java.util.*;
public class FinalTrace {
public static <Int> void main(String[] args) {
// TODO Auto-generated method stub
ArrayList <Int> list = new ArrayList <Int>();
list.add(100, null);
list.add(200, null);
int num = (int) list.get(1);
System.out.println("Number at index 1 in your arraylist: " +
num);
**list.set(2, 500);
System.out.print("The current numbers in your arraylist: ");
for (int i=0; i < list.length; i++)
System.out.print(list.get(i) + " ");
System.out.println("\n----------------------");**
int [] arr = new int[3];
getValues(arr);
System.out.print("The numbers of array that you already entered: ");
for (int i = 0; i < arr.length; i++)
System.out.print(arr[i] + " ");
System.out.println("\n----------------------");
classA obj1 = new classA();
classA obj2 = new classC();
classC obj3 = new classC();
System.out.print(obj2.toString());
System.out.println("----------------------");
try
{
if (num == 200)
throw new FinalException();
}
finally
{
FinalException e;
System.out.println(e.getMessage());
}
}
Fix ArrayList <Int> list = new ArrayList <Int>()
to List <Integer> list = new ArrayList <>()
.修复
ArrayList <Int> list = new ArrayList <Int>()
到List <Integer> list = new ArrayList <>()
。 The boxed int
is Integer
.装箱的
int
是Integer
。
Also, Collections to not have length
like an array.此外, Collections 没有像数组那样的
length
。 Correct to list.size()`.更正 list.size()`。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.