Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Explanation of How Java Stream Works

I have a definition of a Stream such as: "They are wrappers around a data source, allowing us to operate with that data source and making bulk processing convenient and fast. "

Can someone give an example and just a basic explanation of how it works such that Stream makes "bulk processing convenient and fast"?

Thank you!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Files.newBufferedReader("/tmp/foo").lines().map(...)...collect(...);
// or
BufferedReader reader = Files.newBufferedReader("/tmp/foo");
Stream<String> stream = reader.lines();
Collection<String> result = stream.map(...)...collect(...);

Is a convenient way to process a text file using a Stream.

But the work of making it fast/efficient is being done by the BufferedReader, not the Stream.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading