Filter a Map using Stream and Lambda Expression in Java

To filter a Map using Stream and Lambda Expression in Java, we will use the filter() method of Stream object which will be retrieved from Entry object of Map object with Lambda Expression as filter a List. How is it in details? Let learn together in this tutorial.

Example, I have the following Map object as below:

Before Java 8, to filter this Map and only get the age of Khanh, we can write the code as below:

Result:

Filter a Map using Stream and Lambda Expression in Java

Since Java 8, we can re-write this code as below:

Result:

Filter a Map using Stream and Lambda Expression in JavaHere you can also filter a Map and return a new Map as below:

Result:

Filter a Map using Stream and Lambda Expression in Java

 

Add Comment