Reputation:
I'm trying to put the ints
into the Arraylist myList
but Eclipse is pointing to the error:
The type of the expression must be an array type but it resolved to ArrayList<Integer>
I tried to convert from primitive type into Object type but still getting the same error. COuld smb please help me out with that ?
import java.util.*;
public class RemoveDuplicates {
public static void main(String[] args){
int[] myArray = {1,1,2,3,4,5,6,7,8,8,9,9,99};
ArrayList<Integer> myList = new ArrayList();
for(int i = 0; i < myArray.length; i++){
for(int j = 1; j < myArray.length; j++){
if(myArray[i] == myArray[j]){
myList.add(myList[i]);
}
}
}
}
}
Upvotes: 2
Views: 12618
Reputation: 10810
You can't get elements from a list using this syntax.
myList[i]
Which is only valid for arrays. Instead, use the
myList.get(i);
method. More likely though you meant to put myArray[i]
there.
Upvotes: 7