What is the best way to remove null items from a list in Groovy?
ex: [null, 30, null]
want to return: [30]
I think you'll find that this is the shortest, assuming that you don't mind other "false" values also dissappearing:
println([null, 30, null].findAll())
public Collection findAll() Finds the items matching the IDENTITY Closure (i.e. matching Groovy truth). Example:
def items = [1, 2, 0, false, true, '', 'foo', [], [4, 5], null] assert items.findAll() == [1, 2, true, 'foo', [4, 5]]