マーサー:
私は、ユーザーのリストを持って、私は、ID <3で私のリストからユーザーを削除したいです
実際に私は、次の操作を行います。
[...]
int pid1 = 1;
int pid2 = 2;
int pid3 = 3;
Predicate<Person> personPredicate1 = p-> p.getPid() == pid1;
Predicate<Person> personPredicate2 = p-> p.getPid() == pid2;
Predicate<Person> personPredicate3 = p-> p.getPid() == pid3;
list.removeIf(personPredicate1);
list.removeIf(personPredicate2);
list.removeIf(personPredicate3);
[...]
私は右の方法を使用していないと思いますか?
彼らは次のとおりでした:
シングルを使用してremoveIf
:
list.removeIf(p -> p.getPid() < 3);
EDIT:
あなたが投稿エラーに基づいて、あなたは可能ではない不変コレクションから要素を削除しようとしています。
あなたは、元のコピーを作成することができますList
コピーからと削除の要素を:
List<Person> copy = new ArrayList<>(list);
copy.removeIf(p -> p.getPid() < 3);