當判斷一個Item是否在集合中,比如List,Map,Array等,只可以判斷真,不可以判斷假。
如果執著判斷,也可以通過設置標志位去實現,這樣代碼就會顯得臃腫,效率低下。
比如
list.forEach(_item->{// remove hyphenif(!pnHyphenExceptionList.contains(_item)) {_item.settemCode(_item.getItemCode().replaceAll("-", ""));
}通過循環判斷假,此方法不可取pnHyphenExceptionList.forEach(_pn->{if(!_item.getStockItemCode().equals(_pn)) {_item.settemCode(_item.gettemCode().replaceAll("-", ""));}
});}