Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Java 10 questions

Java Lambda Expressions & Streams (Java 8+)

Write clean functional Java. Master lambda shorthand, stream filters, collectors, map-reductions, and parallel pipelines.

More Java
Interview questions 1–10 of 10
1

What is a lambda expression in Java and what problem does it solve?

A lambda expression is a concise way to represent an anonymous function - a block of code that can be passed a...

Read answer →
2

What is a functional interface in Java?

A functional interface is an interface with EXACTLY ONE abstract method, making it eligible to be implemented...

Read answer →
3

What is the Stream API in Java and how does it differ from Collections?

AspectCollectionStreamStorageStores data in memoryNo storage - computes elements on demandMutabilityCan add/re...

Read answer →
4

What is the difference between map() and flatMap() in Java Streams?

MethodTransforms toUse casemap()Stream<R> - one output per input, may be nestedSimple 1-to-1 transformationfla...

Read answer →
5

What are common Stream terminal operations like collect(), reduce(), and forEach()?

Terminal operations trigger the actual execution of a stream pipeline and produce a result (or side effect), a...

Read answer →
6

What are method references in Java, and what are their different types?

Method references are a shorthand for lambda expressions that simply call an existing method, using the :: syn...

Read answer →
7

What is Optional in Java and how does it help avoid NullPointerException?

Optional<T> is a container object that may or may not hold a non-null value, forcing callers to explicitly han...

Read answer →
8

What is the difference between intermediate and terminal operations in Java Streams?

TypeReturnsExecutionExamplesIntermediateAnother StreamLazy - not executed until a terminal op is calledfilter,...

Read answer →
9

How do you use parallel streams in Java, and when should you avoid them?

parallelStream() splits the source data across multiple threads (using the common ForkJoinPool) to process ele...

Read answer →
10

What is the difference between Collectors.toList() and Stream.toList() in modern Java?

MethodAvailable sinceReturned list mutabilitycollect(Collectors.toList())Java 8Typically mutable (ArrayList),...

Read answer →