我要删除的元素,如果它是存在于链表而迭代数的数组爪哇链接列表中删除对象的方法
for(int num : numbers)
{
if(l.contains(num))
{
l.remove(num);
}
}
但是,它试图而不是在索引NUM去除元件,在链表中寻找数字。
的Javadoc有这个方法
remove(Object o)
Removes the first occurrence of the specified element from this list, if it is present.
如何使用它?
使用'l.remove(新的整数(NUM));' –
另外,不要使用'为each'。 – MikeTheLiar
谢谢,它的工作。 那是因为如果我们使用一个原始类型,它需要它的索引?所以我们把它包装为对象? – user2133404