Java 8  flatMap...!

Java 8 flatMap...!

Broadly stream operations are classified as intermediate and terminal operations. flatMap is an intermediate operation, which returns a new stream. Intermediate operations are classified as stateless and stateful operations based on need for sharing information between elements when processing them. flatMap is a stateless intermediate operation

Following example will help you to understand this flatMap and a possible example scenario. Let us consider a zoo and the list of animals in it. Then we can use the flatMap to get an aggregate of animals in a list of Zoo. If we use the Pre-Java8 approach, we would be doing this by using multiple for-loops. Now the same can be achieve with Java 8 Stream API as below.

so basically i have shown a simple demo for this , so below is the pojo class

and below is the main class in which i have applied flat map as shown below



要查看或添加评论,请登录

?? ??Saral Saxena ???????的更多文章

社区洞察

其他会员也浏览了