A Consumerreceives the input and processes it (ie, "consumes" it).
A Consumer<String>consumes one Stringat a time.
In the sample code Consumeris System.out.println.
You can create Stream<String>to separate the input Stringand pass all the elements of this Streaminto Consumer<String>by calling forEach():
Consumer<String> cons = System.out::println;
Arrays.stream(names.split(" ")).forEach(cons);
Of course, there is no need to separate this fragment into two lines:
Arrays.stream(names.split(" ")).forEach(System.out::println);
source
share