-3

It just says:

Returns a sequential Stream with this collection as its source.

This method should be overridden when the spliterator() method cannot return a spliterator that is IMMUTABLE, CONCURRENT, or late-binding. (See spliterator() for details.)

But I can't find any code showing how it creates and returns the new Stream.

double average = roster
.stream()
.filter(p -> p.getGender() == Person.Sex.MALE)
.mapToInt(Person::getAge)`enter code here`
.average()
.getAsDouble();
  • roster is a List<Person> instance of ArrayList<Person>
  • Person is a simple class that represents a person
Community
  • 1
  • 1

1 Answers1

2

Basically the whole stream implementation is package private so you won't get anything showing up at docs.oracle.com.

But take a look a look at the source code here: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/util/stream

You can start with StreamSupport which most classes uses to create the various streams.

KasperNielsen
  • 51
  • 1
  • 2
  • 2
    There exists only one (abstract) j.u.stream.Stream implementation: j.u.stream.ReferencePipeline which gets further specialized into ReferencePipeline.Head for the source stage of a pipeline and ReferencePipeline.StatefulOp / ReferencePipeline.StatelessOp for stateful / stateless intermediate stages of a pipeline. The same for j.u.stream.Double/Int/LongStream => j.u.stream.Double/Int/LongPipeline with corresponding Head, StatefulOp and StatelessOp static nested classes. – Stefan Zobel May 24 '15 at 14:54