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