Thursday, February 15, 2007

How can I remove value "2"?

In Groovy, you can remove an object from a list by using remove(int index) or remove(object obj). But if I have a list of ints, how can I remove an object by "value" rather than the index?

def list = [2, 1, 3]

list.remove(2)
assert list == [1, 3] // throws AssertionError, 'cause list = [2, 1]

No comments: