【发布时间】:2019-07-26 05:47:43
【问题描述】:
我正在尝试使用Iterator 从ArrayList 中删除给定的String 数组。获取给定应用程序的列表。我正在使用我的课本作为资源,但我很困惑为什么会收到错误cannot find symbol - method iterator();。我应该使用Iterator 从我的ArrayList 中删除给定的String 吗?还是我应该使用更好的循环?
非常感谢。
public void removeApp(String name)
{
Iterator<App> it = name.iterator();
while(it.hasNext()) {
App app = it.next();
String appName = app.getName();
if (appName.equals(name)) {
it.remove();
System.out.println(appName + "has been removed.");
}
}
System.out.println("Can't find app. Please try again.");
}
【问题讨论】:
-
@AnuragSrivastava 这似乎是一个与这个问题完全不同的问题。
标签: java if-statement arraylist while-loop iterator