World 16 of 26 · Intermediate

🌊 Streams API

17 Java concepts, each explained step by step with real code, a common trap and practice questions.

  1. What a stream isA pipeline over data: source → intermediate ops → terminal op; not a data structure.
  2. Creating streamscollection.stream(), Stream.of, Arrays.stream, IntStream.range, iterate, generate.
  3. LazinessNothing runs until a terminal operation; element-by-element processing.
  4. filter & mapSelecting and transforming elements.
  5. flatMapFlattening nested structures into one stream.
  6. sorted, distinct, limit, skipStateful intermediate operations.
  7. Terminal operationsforEach, count, min/max, anyMatch/allMatch/noneMatch, findFirst/findAny.
  8. reduceIdentity, accumulator, combiner; summing and folding.
  9. Collectors basicstoList, toSet, toMap (duplicate key exception), joining, counting.
  10. groupingBy & partitioningByBuilding maps of groups with downstream collectors.
  11. Primitive streamsIntStream, sum, average, boxed, mapToInt.
  12. Streams are single-useReusing a consumed stream throws IllegalStateException.
  13. Short-circuiting & infinite streamslimit and findFirst make infinite streams finite.
  14. Side effects & peekWhy lambdas in streams should be stateless; peek is for debugging.
  15. Parallel streamsForkJoinPool, when parallel helps and when it hurts; ordering.
  16. Stream.toList vs collect(toList())Unmodifiable vs no guarantee.
  17. Stream gatherersJava 24 gather() with windowFixed, windowSliding, fold, scan.