从Groovy的列表中删除空项目 [英] Remove null items from a list in Groovy

查看:144
本文介绍了从Groovy的列表中删除空项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例: [null,30,null]



想返回: [30]

如果您不想保留原始列表,那么这里是一个答案。

  void testRemove(){
def list = [null,30,null]

list.removeAll([null])

assertEquals 1,list。 size()
assertEquals 30,list.get(0)
}

在方便的花哨的单元测试中


What is the best way to remove null items from a list in Groovy?

ex: [null, 30, null]

want to return: [30]

解决方案

here is an answer if you dont want to keep the original list

void testRemove() {
    def list = [null, 30, null]

    list.removeAll([null])

    assertEquals 1, list.size()
    assertEquals 30, list.get(0)
}

in a handy dandy unit test

这篇关于从Groovy的列表中删除空项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆