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

标签 java groovy

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

相关文章:

java - 在 Java 中使用 Visual Studio Code 的 Azure Functions 项目

Java 线程同步 - Thread.sleep() 方法未按预期工作

java - @NotNull 原语约束,为什么?

Grails - 没有方法签名适用于参数类型

arraylist - 合并 2 个列表,同时保留原始数据

grails - Groovy/Grails 代码清理建议,请!

java - Struts 2 - 了解 OGNL 和参数拦截器之间的工作

java - Box.add() 线程安全吗?

java - Groovy 基础——运行时行为和封装

ubuntu - Jenkins 突然显示 "wrapper script does not seem to be touching the log file"并超时并显示 FAILURE 消息