There are more than 1 commands in the Java 8 foreach function
•
Java
Is it possible to import the map.xml in Java 8 Multiple commands used in foreach function?
So instead of:
map.forEach((k,v) -> System.out.println(k + "=" + v));
What I want to do is as follows:
map.forEach((k,v) -> System.out.println(k)),v.forEach(t->System.out.print(t.getDescription()));
Let's assume that K is a string and V is a set
Solution
Lambda syntax allows two body definitions:
>The expression returned by a single value, for example: X – > x * 2 > multiple statements, enclosed in curly braces, for example: X – > {x * = 2; returns X;}
The third special case is that it allows you to avoid using curly braces when calling the void return method, such as system. X – > out. println(X).
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码