gpt4 book ai didi

java - 从常规列表中删除特定值

转载 作者:行者123 更新时间:2023-12-01 14:32:46 25 4
gpt4 key购买 nike

我的代码片段如下,我想忽略/删除条件检查的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com