Java 8 - For Each and removeIf
There's no need for the forEach
, the Lambda expression will work on all elements of the set
ints.removeIf(i -> i%2==0)
removeIf: "Removes all of the elements of this collection that satisfy the given predicate"
Simply...
For each element (i
) in the set (ints
), remove it if (removeIf
) the predicate (i%2==0
) is true for this element (i
). This will act on the original set and return true if any elements where removed.