Functional Java & Streams: complete interview question bank
This is the Functional Java and Streams pass I would do before a Java backend interview. It pulls together the questions that look like syntax on the surface, but really test whether you understand target typing, pipeline execution, collectors, ordering, parallel costs and coding trade-offs.
Use it like a mock interview. Read the question, say your answer out loud first, then open the model answer and check whether you led with the right default, the trade-off and the edge case.
Treat this as the final pass after the topic pages: lambdas, stream basics, stream operations and stream puzzles.
Lambdas & functional interfaces
6 questionsLambda questions check whether you can connect the short syntax to the interface contract, capture rules and runtime behavior instead of treating lambdas as magic callbacks.
What is a functional interface, and why would you add @FunctionalInterface?
Tests SAM rule, default methods, annotation
Show answerHide answer
Model answer
A functional interface has exactly one abstract method, so a lambda or method reference has one target shape to implement. Default and static methods do not count against that rule. @FunctionalInterface is optional, but it makes the compiler protect the contract if someone later adds a second abstract method.
This is the core idea in Lambdas and functional interfaces.
How I’d say it in the interview
"The annotation doesn't create lambda behavior. It documents and enforces the one-abstract-method contract."
Signals depth
Mentioning that Java reused interfaces rather than adding a separate function type.
Red flags
Saying any interface used by a lambda is automatically functional.
Follow-ups interviewers ask next
What if the interface has one abstract method and three default methods?
It is still functional because defaults already have bodies.
Why does var f = s -> s.length() not compile?
Tests target typing, poly expressions, lambda types
Show answerHide answer
Model answer
A lambda needs a target type from the surrounding context. var asks the initializer for its standalone type, but the lambda does not have one by itself. Assign it to Function<String, Integer>, ToIntFunction<String>, or another explicit functional interface.
Review Lambdas and functional interfaces for the target-typing model.
How I’d say it in the interview
"The lambda text is not born as a Function. The target type tells the compiler what s is and what the return value must be."
Signals depth
Calling lambdas poly expressions and mentioning primitive functional interfaces when boxing matters.
Red flags
Assuming the compiler can infer String from s.length() alone in every context.
Follow-ups interviewers ask next
What if two overloads accept similar functional interfaces?
The call may be ambiguous. Use a typed variable, a cast, or a clearer API.
How is this inside a lambda different from this inside an anonymous class?
Tests lexical scope, anonymous classes, receiver binding
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Why must a local variable captured by a lambda be final or effectively final?
Tests capture, stack frame, reassignment
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
When would you prefer a lambda over a method reference?
Tests readability, method references, captured constants
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
How do you compose predicates without turning the code into a unreadable chain?
Tests Predicate.and, naming, composition
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Stream basics
6 questionsStream basics questions test whether you can see the source, the lazy pipeline, the terminal operation and the one-shot nature of streams.
What is a stream, and how is it different from a collection?
Tests source, pipeline, storage
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
What does laziness mean in a stream pipeline?
Tests laziness, terminal operation, vertical execution
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Why can count() skip a peek on Java 21?
Tests SIZED, count optimization, side effects
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Why does reusing a stream throw IllegalStateException?
Tests one-shot streams, terminal operation, supplier pattern
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
When would you choose findFirst over findAny?
Tests encounter order, short-circuiting, parallel streams
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Why use IntStream instead of Stream<Integer> for numeric work?
Tests primitive streams, boxing, numeric terminals
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Operations with streams
6 questionsOperations questions check whether you choose the right stage for the shape change and understand where ordering, state and side effects sneak in.
Explain map versus flatMap using orders and line items.
Tests one-to-one, one-to-many, nested streams
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
When are skip, limit, takeWhile and dropWhile the right tools?
Tests slicing, prefix operations, encounter order
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
How do you sort by two fields and keep distinct business keys?
Tests Comparator, distinct, distinctBy trade-off
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
What is wrong with reduce(10, Integer::sum) on a parallel stream?
Tests reduce identity, associativity, parallel partitions
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Why is mutating an ArrayList inside parallelStream().forEach a bug?
Tests side effects, non-interference, parallel forEach
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Why can distinct().limit(3) hang on an infinite stream?
Tests infinite streams, stateful operations, operation order
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Collectors
6 questionsCollectors questions test whether you can build result containers deliberately: maps, grouped data, immutable results, downstream collectors and custom accumulation.
When would you use toList(), Collectors.toList() and toUnmodifiableList()?
Tests list collectors, mutability, null policy
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Explain groupingBy with a downstream collector.
Tests classifier, downstream collector, map supplier
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
How do you handle duplicate keys with Collectors.toMap?
Tests duplicate keys, merge function, map supplier
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
What does collectingAndThen buy you?
Tests finishing step, immutable results, maxBy unwrap
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
When would you write a custom collector?
Tests supplier, accumulator, combiner, finisher
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
How do immutable collection collectors differ from unmodifiable views?
Tests immutable collections, defensive copying, views
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Parallel streams & Spliterator
6 questionsParallel stream questions are judgment questions. They test whether you understand splitting, the common pool, ordering costs and why parallel does not mean automatically faster.
When does a parallel stream usually help?
Tests CPU-bound work, splitting, overhead
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Why can ordered parallel operations be slower?
Tests encounter order, coordination, forEachOrdered
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
What is the common fork-join pool issue with parallel streams?
Tests common pool, blocking, isolation
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
What does a Spliterator do?
Tests traversal, splitting, characteristics
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Why are ArrayList and LinkedList different sources for parallel streams?
Tests splitting cost, locality, source shape
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
What makes a collector safe or unsafe for parallel collection?
Tests collector combiner, shared state, characteristics
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Stream coding problems
6 questionsCoding-problem questions test whether you can name the pattern first: count, group, rank, flatten, zip, partition or switch to a loop when a stream makes the algorithm worse.
Find the second-highest distinct salary.
Tests distinct, sorted, skip, Optional
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Count word frequency and return it sorted by count descending.
Tests groupingBy, counting, sorted entries, LinkedHashMap
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Group employees by department and average salary.
Tests groupingBy, averagingInt, map supplier
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Find the first non-repeating character in a string.
Tests LinkedHashMap, codePoints, ordering
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Zip two lists by index.
Tests IntStream.range, indices, list access cost
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
When should you abandon a stream solution in a coding problem?
Tests algorithm choice, running state, merge sorted lists
Model answer, how to say it, 1 follow-up: unlock with the Java Pass
Premium question set
Keep reading with the Java Pass
The rest of this question set is part of Java One-Stop Interview Prep: in-depth explanations, diagrams, model answers and how to say them in the interview.
From ₹199 · one-time payment · No auto-renewal
Topic question sets in Functional Java & Streams
- Lambdas & functional interfaces: interview questions & scenarios
- Stream basics: interview questions & scenarios
- Operations with streams: interview questions & scenarios
- Collectors: interview questions & scenarios
- Parallel streams & Spliterator: interview questions & scenarios
- Stream coding problems: interview questions & scenarios