Skip to content
Advertisement

How to print List of String array array using lambda in Java [closed]

This is my code:

JavaScript

How to print the List that contains String array using Lambda. Thank you in advance.

Advertisement

Answer

To convert a for-each loop into a forEach call the general pattern is:

JavaScript

A lambda of the form (x, y) -> { statements; } is mostly equivalent to a method of the form:

JavaScript

Return type and parameter type are inferred automatically by the compiler when a lambda is encountered.


So in your case that would be:

JavaScript

You could also use streams to first map each object to a string representation and then output each item in a terminal operation:

JavaScript

Since System.out.println expects exactly one argument which matches the lambda argument, it could be replaced with a method reference, which can be more readable in some cases: .forEach(System.out::println)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement