liveBook · Manning

Collection.stream

As explained in 100 Java Mistakes and How to Avoid Them

Collection.stream is a Java Collection operation that creates a sequential Stream over the collection's elements.

Use collection.stream() to create a stream from a collection. Do not substitute Stream.of(collection): Stream.of() is for a single element or an array, while collection.stream() operates on the collection's elements. section 8.2

The single-object versus collection mistake

When processing a collection, choose collection.stream() rather than Stream.of(list). The latter treats the list as the single input value, so it does not provide the intended stream of collection elements. section 8.2

How 100 Java Mistakes and How to Avoid Them covers it

How deep it goes
Distinguishes the two stream-creation APIs but does not develop stream pipelines or stream execution internals.
Examples
Uses Stream.of(list) as the faulty construction and contrasts it with collection.stream().
What it assumes
Assumes familiarity with Java collections, objects, arrays, and streams.
What you can do after
Apply it via the Java API by choosing collection.stream() when streaming a collection's elements.
How it connects
Connects Stream.of with collections, streams, and related single-object versus collection operations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Java Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.