When does a stream pipeline run?
QuizEasy-MediumJava onlyAsked in: Accenture, Capgemini, TCS
A stream is a pipeline of steps over a collection. peek runs a side action on each element, and collect ends the pipeline and gathers the result. What does this print?
Stream<String> s = Stream.of("a", "b")
.peek(x -> System.out.print("peek " + x + " "))
.map(String::toUpperCase);
System.out.println("no terminal yet");
System.out.println(s.collect(Collectors.toList()));no terminal yetthenpeek a peek b [A, B]peek a peek b no terminal yetthen[A, B]no terminal yetthen[A, B]
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.