Let’s say we have a collection; it could be a list or set, it doesn’t really matter as long as it is a collection, and we want to iterate over it. Often, we make this mistake: we immediately open stream whenever we think of working with a collection; since java 8, it has, sort of, become our second nature, which is excellent. Hurray!
However, I have seen this in many production codes. Well, the outcome indeed serves our purpose, but it may not be necessary to open a stream. All the collection interface has a for each method in them, and it does the same thing we are supposed to do here. However, creating a stream creates a new object that is just needed to get our desired output.
#java8, #stream #java #stream #forEach #iteration
On this page of the site you can watch the video online Avoid using stream for simple iteration with a duration of hours minute second in good quality, which was uploaded by the user A N M Bazlur Rahman 04 March 2022, share the link with friends and acquaintances, this video has already been watched 318 times on youtube and it was liked by 15 viewers. Enjoy your viewing!