RyanLynch RyanLynch - 1 year ago 119
Groovy Question

Remove null items from a list in Groovy

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


[null, 30, null]

want to return:

Answer Source

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

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


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

in a handy dandy unit test