I didn't know you could do that with Java Streams!
summary
Shows concrete rewrites: replace collect-then-index-or-empty with findAny vs findFirst for order-of-magnitude fewer elements processed; swap nested loops for flatMap + Optional.stream to drop isPresent/get anti-patterns; use collectors like collectors.joining, groupingBy with a merge function to pick the cheapest per category, and collectors.counting instead of manual maps. Uses IntStream.rangeClosed and reduce to sum BigDecimal, demos parallelStream speeding a sqrt+sum over 100,000 numbers, and recommends JMH microbenchmarks.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 1:15When to use Streams effectively
- 3:20Basic Stream operations
- 5:04findAny vs findFirst
- 9:40AnyMatch, nonMatch and allMatch for conditions
- 11:46FlatMap for nested collections
- 15:12Collectors joining strings
- 17:42Min and max with comparators
- 19:08MapToInt and IntStream.range
- 21:14Reduce for aggregation
- 23:22Instance checks with class literals
- 25:13Parallel streams for threading
- 27:42Sorted and limit for top elements
- 29:49Count and distinct for uniqueness
- 31:54Immutable lists in Java 16+
- 32:56Grouping and mapping in collectors
- 38:40Collectors mapping nested
- 40:45Collectors counting frequencies
- 42:34Resources and closing
related talks
51mIf Streams Are So Great, Let’s Use Them Everywhere... Right??
02h 25mExploring Collectors
55mTransforming Your Code to Java 8
53mExploring Collectors: A Powerful Utility Class in the JDK
01h 57mJourney’s End: Collection and Reduction in the Streams API
55mExploring Collectors
47mWhen Greed Is Good: Understanding Java Stream Performance
39mLevel Up Your Java Streams with Gatherers
