June 2018
Intermediate to advanced
280 pages
7h 46m
English
The intermediate stream operations are applied lazily; this means that the actual call is done only after the terminal operation gets called. In the following code, using names randomly generated online using http://www.behindthename.com/random/?, the search will stop once the first valid name is found (it just returns a Stream<String> object):
jshell> Stream<String> stream = Arrays.stream(new String[] {"Benny Gandalf", "Aeliana Taina","Sukhbir Purnima"})....> map(x -> { System.out.println("Map " + x); return x; })....> filter(x -> x.contains("Aeliana"));stream ==> java.util.stream.ReferencePipeline$2@6eebc39ejshell> stream.findFirst();Map Benny GandalfMap Aeliana Taina$3 ==> Optional[Aeliana Taina]
Stream intermediate ...
Read now
Unlock full access