有用户列表。 我想从名单上删除id
其实我是这么做的:
[.]
int pid1=1;
int pid2=2;
int pid3=3;
predicatepersonpredicate1=p-p.getpid (==PID 1;
predicatepersonpredicate2=p-p.getpid (==PID 2;
predicatepersonpredicate3=p-p.getpid (==PID 3;
list.removeif(Personpredicate1;
list.removeif(Personpredicate2;
list.removeif(Personpredicate3;
[.]
你认为不用正确的方法吗?
解决方法:
使用单个移除if :
list.removeif(p-p.getpid ) ) 3;
编辑:
根据发出的错误,您试图从不变集合中删除元素。 这是不可能的
可以创建原始列表的副本,并从副本中删除元素。
列表复制=new ArrayList (列表;
复制.移除if (p-p.getpid ) ) 3;
标签: java,predicate
资料来源: https://codeday.me/bug/2019 07 22/1499909.html