Let’s say I have a code that filters some elements from one list and then adds the elements to the second list and then removes the elements from the third list. I can do it using a lambda and 2 instructions, but wouldn’t it be easier and more readable to have a variable length parameter list in the terminal operations?
Instead of
<code>List a, b, c; // initialize and fill the lists
a.stream()
//filtering
.forEach(e -> {
b.add(e);
c.remove(e);
});
</code>
<code>List a, b, c; // initialize and fill the lists
a.stream()
//filtering
.forEach(e -> {
b.add(e);
c.remove(e);
});
</code>
List a, b, c; // initialize and fill the lists
a.stream()
//filtering
.forEach(e -> {
b.add(e);
c.remove(e);
});
we could have
<code> .forEach(b::add, c::remove);
</code>
<code> .forEach(b::add, c::remove);
</code>
.forEach(b::add, c::remove);