java中的迭代器和while

问题描述

如果小于5,我必须检查目录中每个人的标识符的值,然后必须删除目录中的注释和人员。我试过了:

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"

在目录中,我根据标识符添加了它们。例如:

yourImageView.clipsToBounds = true

我一直在尝试,但我不知道在这里做什么。

解决方法

我认为您想说的是您想从 persons 中删除内容,但您也想删除要从地图中删除的内容。

您可以分三步完成:

  1. 获取您要删除的内容
  2. 将它们从 persons 中删除
  3. 也将它们从 catalog 中删除

像这样:

// 1.
List<Person> toRemove = persons.stream().filter(p -> p.obtineIdentificator() < 5).collect(toList());

// 2.
persons.removeAll(toRemove);

// 3.
toRemove.stream().map(Person::obtineIdentificator).forEach(catalog::remove);
// or (amongst other ways)
catalog.keySet().removeAll(toRemove.stream().map(Person::obtineIdentificator).collect(toSet());
,

您可以使用以下代码。

ListIterator<Person> iter = persons.listIterator();
while(iter.hasNext()){
    if(iter.next().getObtineIdentificator() < 5){
        iter.remove();
    }
}