What is the best way to remove null items from a list in Groovy?
ex: [null, 30, null]
[null, 30, null]
want to return: [30]
[30]
Just use minus:
[null, 30, null] - null
This does an in place removal of all null items.
myList.removeAll { !it }
If the number 0 is in your domain you can check against null
myList.removeAll { it == null }