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
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 <>()
. The boxed int
is Integer
.
Also, Collections to not have length
like an array. Correct to list.size()`.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.