Print ArrayList using Lambda Expression in Java 8

This article will help you to understand Print ArrayList using Lambda Expression in Java 8.

Java Program of Print ArrayList using Lambda Expression in Java 8



Let’s understand each line of program

Line 12: Straightforward way to print arraylist in java

The lambda expression is made of two parts the one on the left of the arrow symbol (->) listing its parameters and the one on the right containing its body.

Line 17: In this case the compiler automatically figures out that the lambda expression has the same signature of the only non implemented method of the Consumer interface (that for this reason is called a functional interface) and treat the first as it was an instance of the second, even if the generated bytecode could potentially be different.

Line 20: The declaration of the types of the lambda expression arguments can be, in the biggest part of cases, inferred by the compiler and then omitted.

Line 23: We can rewrite statement even more concisely using a method reference, another feature introduced in Java 8. More in details in Java 8 it is possible to reference both a static and an instance a method using the new :: operator as in.

Leave a Reply

Your email address will not be published. Required fields are marked *