我的代码片段如下,我想忽略/删除条件检查的 else 部分列表中的值。 OfferRecords.remove(tariffOffer) 似乎不起作用
offerRecords.each { tariffOffer ->
handsetData.each { hs ->
if (tariffOffer.HANDSET_BAND.stringValue() == hs.HANDSET_BAND?.stringValue()) {
//println 'condition is satisfied and set the handset id ****** '
handset.add(hs.HANDSET_PKEY_ID?.stringValue())
}
if (handset.size() > 0) {
// need to call a method
recHandset = applyHandsetRulesCHL(tariffOffer, handset)
}
else {
// ignore/remove the tariffOffer
offerRecords.remove(tariffOffer) // i know it doesn't serve the purpose
}
最佳答案
只需在处理之前过滤您的列表:
def filteredList = handsetData.findAll{handset.size() > 0}
并处理过滤结果。顺便说一句,我无法理解 each{}
body 中的 handset
是什么,但我想您已经明白了。
关于java - 从常规列表中删除特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16730738/