- Executors
-
Learn
Learn Python Runnable examples, NumPy, pandas, and more Learn AI / Machine LearningNeural networks, ML and LLMs from scratch Learn C & C++ Pointers, memory, STL, and modern C++ Learn C#C# basics, OOP, LINQ, async, and .NET exercises Learn MatplotlibLine, bar, scatter and pie charts with live visualizers Learn RustOwnership, traits, error handling, and threads Learn GoSlices, interfaces, goroutines, and channels Python Algorithms Search, sorting, recursion, and visualizers O(n) C & C++ Algorithms Compare algorithms implemented in C and C++ Coding for Kids Learn to code by playing!
- QuizzesNew
- ChallengesNew
- For TeachersNew
- Updates
- Buy me a coffee
Java Lambdas & Streams Quiz
This Java quiz tests lambdas and the Stream API that came with Java 8. You will predict what pipelines print, see why streams are lazy and single-use, and match lambdas to functional interfaces.
Sample question
Question 1 of 10What does this print?
import java.util.List;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
List<Integer> nums = List.of(1, 2, 3, 4, 5, 6);
List<Integer> result = nums.stream()
.filter(n -> n % 2 == 0)
.map(n -> n * n)
.collect(Collectors.toList());
System.out.println(result);
}
}
Show the answer
A. [4, 16, 36] filter keeps the even numbers 2, 4 and 6, then map squares each of them. The original list is not changed; collect builds a new one.
What this quiz covers
filter,map,reduceandcollect- Lazy evaluation and the order in which elements flow
- Streams can be used only once
- Effectively final variables in lambdas
Collectors.joining,groupingBy,Optionaland functional interfaces
Questions people ask
Do I need an account?
No. Anyone can play. Sign in to keep your XP, streak, badges and history.
Can I retake it?
Yes. Your best score is kept, and the questions and answers are shuffled each time.