Post

Java2blog
Java2blog@java2blog·
How to write a lambda expression in a way that you will never forget. A Thread 🧵
English
1
1
1
396
Java2blog
Java2blog@java2blog·
Step 1: Go to the source code functional interface for which you need to write lambda expressions and copy the parameters of its abstract method. For example: Let's say you want to write lambda expression for Consumer.
Java2blog tweet media
English
1
0
0
50
Java2blog
Java2blog@java2blog·
Step 2 : Put Array Operator
Java2blog tweet media
English
1
0
0
44
Java2blog
Java2blog@java2blog·
Step 3:  Write the implementation similar to a method which takes String as input and returns nothing. Please note that we need to use curly braces {} and a return statement when we want to execute multiple statements.
Java2blog tweet media
English
1
0
0
40
Java2blog
Java2blog@java2blog·
Let's use this method to write the Function functional interface.
Java2blog tweet media
English
1
0
0
32
Java2blog
Java2blog@java2blog·
Now, let's say we are given a list of employee objects listOfEmployees and we need to obtain a list of the names of employees. Here, we will use the map() method of the Stream API that takes a Function as a parameter.
Java2blog tweet media
English
1
0
0
33
Java2blog
Java2blog@java2blog·
That's a wrap! Please follow @java2blog for more such content.
English
0
0
0
120
Paylaş