【发布时间】:2019-10-26 06:01:28
【问题描述】:
我正在根据它是谁创建一个 Java 应用程序?现在我正在制作一种方法,在回答问题时我想要其他卡片。
我有两个列表:
列表是一个 ImageView 列表,其中有 24 个卡片必须代表的图像视图。
另一个列表是 24 个地图对象的列表。
现在,如果图像视图的 ID 与 ImageView 中的卡片名称相同,我想从 ImageView 列表中删除 ImageViews。
我尝试在 foreach 中执行 foreach,然后从列表中删除一个项目,但我无法弄清楚。
我创建的方法:
public List<ImageView> getImageViews(List<Card> newCards){
for (ImageView imageView: new ArrayList<>(allCards)) {
String imageName = imageView.getId().toLowerCase();
for (Card card: new ArrayList<>(newCards)){
String cardName = card.getName().toLowerCase();
if (!imageName.equals(cardName)){
allCards.remove(imageView);
}
}
}
return allCards;
}
【问题讨论】: