当判断一个Item是否在集合中,比如List,Map,Array等,只可以判断真,不可以判断假。
如果执着判断,也可以通过设置标志位去实现,这样代码就会显得臃肿,效率低下。
比如
list.forEach(_item->{
// remove hyphen
if(!pnHyphenExceptionList.contains(_item)) {
_item.settemCode(_item.getItemCode().replaceAll("-", ""));
}
通过循环判断假,此方法不可取
pnHyphenExceptionList.forEach(_pn->{
if(!_item.getStockItemCode().equals(_pn)) {
_item.settemCode(_item.gettemCode().replaceAll("-", ""));
}
});
}