Skip to content
Sharp

Streams & functional interview questions

Lambdas, intermediate vs terminal operations, Optional.

4 questions with answers and explanations · 3 flashcards

Key ideas

  • A stream pipeline is source → zero or more intermediate ops (lazy) → one terminal op (triggers execution).
  • Pipelines process elements one at a time and short-circuit (findFirst, anyMatch, limit).
  • map transforms 1→1; flatMap transforms 1→many and flattens.
  • Optional.orElse(x) always evaluates x; orElseGet(supplier) only when empty.

Questions

  1. What does this print?What does this code output?Easy
  2. Which of these is a terminal stream operation?Multiple choiceEasy
  3. What does this print?What does this code output?Hard
  4. Complete the statements about Optional.Drop-down clozeMedium