Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Streams Examples

Build Maintainability Rating Reliability Rating Security Rating

Article

The code refers to the following articles:

Contents

All examples work on the same data model: the records Book and Author, the enum Genre, and the Library class with eleven public-domain classics.

Every class with a main() method is one chapter of the article and prints the outputs shown there. Run one with java -cp target/classes eu.happycoders.streams.<ClassName> after mvn compile:

  • Ch1Intro – the same task as a loop and as a stream; the anatomy of a stream pipeline
  • Ch2Lambdas – lambda expressions, method references, functional interfaces
  • Ch3Sources – creating streams from collections, arrays, ranges, files, and generators
  • Ch4Intermediatefilter(), map(), flatMap(), mapMulti(), distinct(), sorted(), limit(), skip(), takeWhile(), dropWhile(), peek(), gather()
  • Ch5TerminalforEach(), collect() and collectors, toList(), toArray(), reduce(), count(), min(), max(), findFirst(), anyMatch(), and the others
  • Ch6Lazy – lazy evaluation: element-by-element processing, short-circuiting, stateful operations, single use
  • Ch7Parallel – parallel streams
  • Ch8Mistakes – common mistakes and how to avoid them

The code requires Java 25 or newer.


Additional Resources


Java Versions PDF Cheat Sheet

Stay up-to-date with the latest Java features with this free PDF Cheat Sheet!

Java Versions PDF Cheat Sheet Mockup

  • Avoid lengthy research with this concise overview of all Java versions from Java 10 to Java 27.
  • Discover the innovative features of each new Java version, summarized on a single page.
  • Impress your team with your up-to-date knowledge of the latest Java version.

👉 Download the free Java Versions PDF

(Hier geht's zur deutschen Version → Java-Versionen PDF)


The Big O Cheat Sheet

With this free 1-page PDF cheat sheet, you'll always have the 7 most important complexity classes at a glance.

Big O PDF Cheat Sheet Mockup

  • Always choose the most efficient data structures and thus increase the performance of your applications.
  • Be prepared for technical interviews and confidently present your algorithm knowledge.
  • Become a sought-after problem solver and be known for systematically tackling complex problems.

👉 Download the free Big O Cheat Sheet

(Hier geht's zur deutschen Version → O-Notation Cheat Sheet)


HappyCoders Newsletter

👉 Want to stay on top of modern Java? Sign up for the HappyCoders newsletter – Modern Java: new versions & features, performance, and JVM insights – once a month.

(Hier geht's zur deutschen Version → HappyCoders-Newsletter deutsch)


🇩🇪 An alle Java-Entwickler:innen, die durch fundierte Kenntnisse über Datenstrukturen besseren Code schreiben wollen

Trage dich jetzt unverbindlich auf die Warteliste von „Mastering Data Structures in Java“ ein, und erhalte das beste Angebot!

Mastering Data Structures Mockup

👉 Zur Warteliste

About

Example code for the HappyCoders article “Java Streams (with Examples)” – stream sources, intermediate and terminal operations, lazy evaluation, parallel streams, and common mistakes

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages