Is it possible to use more than one command in the Map.foreach function that got introduced with Java 8?
So instead:
map.forEach((k, v) ->
System.out.println(k + "=" + v));
I want to do something like:
map.forEach((k, v) ->
System.out.println(k)), v.forEach(t->System.out.print(t.getDescription()));
Lets pretend that k are Strings and v are Sets.
The lambda syntax allows two kinds of definitions for the body:
x -> x*2
x -> { x *= 2; return x; }
A third special case is the one that allows you to avoid using curly braces, when invoking a void
returning method, eg: x -> System.out.println(x)
.
Use this:
map.forEach(
(k,v) -> {
System.out.println(k);
v.forEach(t->System.out.print(t.getDescription()))
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With