表达式的类型必须是数组类型,但必须解析为ArrayList< Integer>. [英] The type of the expression must be an array type but it resolved to ArrayList<Integer>
问题描述
我试图将ints
放入Arraylist myList
,但是Eclipse指向错误:
The type of the expression must be an array type but it resolved to ArrayList<Integer>
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>
我试图从原始类型转换为对象类型,但仍然遇到相同的错误. smb可以帮我解决这个问题吗?
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]);
}
}
}
}
}
推荐答案
您无法使用此语法从列表中获取元素.
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);
方法.尽管您打算将myArray[i]
放在此处的可能性更高.
method. More likely though you meant to put myArray[i]
there.
这篇关于表达式的类型必须是数组类型,但必须解析为ArrayList< Integer>.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!