在Groovy中,你可以使用removeAll方法来移除集合中为空(null)的元素。下面是一个示例代码:

def list = [1, null, 3, null, 5]
list.removeAll { it == null }
println list // 输出: [1, 3, 5]

在这个示例中,我们定义了一个包含空元素的列表list。然后,我们使用removeAll方法来移除所有为空的元素。最后,我们打印输出列表,可以看到空元素已经被成功移除。

groovy param val为空的移除

原文地址: https://www.cveoy.top/t/topic/ivZl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录