How to do it...

We will walk you through the sequence of practical steps that demonstrate how to use the preceding methods and classes:

  1. Write an example of the usage of the R collect(Supplier<R> supplier, BiConsumer<R,T> accumulator, BiConsumer<R,R> combiner) operation of the Stream<T> interface that produces the List<T> object: 
 List<Person> list =     Stream.of(new Person(30, "John"), new Person(20, "Jill"))    .collect(ArrayList::new,             List::add,      //same as: (a,p)-> a.add(p),             List::addAll    //same as: (r, r1)-> r.addAll(r1)    ); System.out.println(list);   //prints: [Person{name:John,age:30}, Person{name:Jill,age:20}]  

In the preceding example, the comments to the accumulator and the combiner demonstrate how these functions can be presented as lambda ...

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.