Reputation: 965
Hey i have an array list of numbers and when i try to convert into int
i get The method intValue() is undefined for the type Object
error. This is the code snippet.
while (1>0) {
a = Integer.parseInt(in.next());
if(a == -999)
break;
else {
list.add(a);
i++;
}
}
int j;
int[] array = new int[list.size()];
for(j=0;j<list.size();j++) {
array[j] = list.get(j).intValue();
}
Upvotes: 0
Views: 2778
Reputation: 68715
It seems you have created a list of objects and not Integers. Hence when you call intValue
then it says that there is no such method for type Object. I would recommend that you define your list as list of Integers using generics. Here is the sample:
List<Integer> list = new ArrayList<Integer>();
If you don't do so then you list created will hold the items of class Object
. And then you need to cast the object fetched from the list everytime to Integer
.
Upvotes: 2