1. The purpose of this post
I would demo how to iterate and print list of Map entries by using java stream.
Say, we have a list of Map<String,String> as follows, we use Vavr to build some java HashMaps as follows:
If you don’t know why does it work, you can refer to this article.
Then we add these maps to a list:
Then the question: how to iterate over this list of maps using java stream?
3. Solution and Code
The solution is using a flatmap:
Run the code, we get this result:
4. How did this work?
You can view this picture to see how the java stream flatmap works:
Iterate over a list of map using java stream is easy.