Streams is introduced in java8 version. It basically helps to write a concise piece of code and it’s functional style of code writing. For the complete piece of code please visit the below mentioned link.
The piece of code for stream iteration is mentioned below :-
In the above case the “forEach” is a terminal operation. And inside the the terminal operation we have to pass functional “Consumer” interface. Which has an unimplemented “accept” method, which will take the variable of “Hotel” class as an argument and will print it out.
But the above piece of code can be re written in a more concise manner by using the lambda expression as mentioned below:-