Auto-unboxing seems to not work when using ListIterator.
The code below throws a compile-time error stating "incompatible types: Object cannot be converted to int"
import java.util.*;
class Input_Array
{
public static void main(String[] args)
{
String x = "36 42 74 98 41 85";
String y[] = x.split(" ");
int p[] = new int [6];
ArrayList<Integer> lst = new ArrayList<>();
int i=0;
for(String v : y)
{
lst.add(Integer.valueOf(v));
}
ListIterator X = lst.listIterator(lst.size());
while(X.hasPrevious())
{
int n=X.previous();
System.out.print(n+" ");
}
System.out.println();
}
}
.
Replacing line 18 with
int n=(int)X.previous();
seems to work pretty good. Isn't auto unboxing(automatic conversion of Object type to their primitive) supported by Listiterators?