Filter and Square Even Numbers
Practice using the Java Streams API to process collections in a clear, declarative style. You will work with a list of integers and apply stream operations such as filtering, mapping, and collecting to produce a transformed result instead of writing traditional loops.
The task is to design a stream-based solution that reads an input list, applies the required conditions, and returns the correct final list while keeping the code readable and efficient. Focus on choosing the right sequence of intermediate operations and a suitable terminal operation so that the behavior is easy to understand and extend.
Algorithm Flow

Recommendation Algorithm Flow for Filter and Square Even Numbers - Budibadu
Best Answers
java - Approach 1
import java.util.List;
import java.util.stream.Collectors;
class Solution {
public static List<Integer> filterAndSquareEven(List<Integer> numbers) {
if (numbers == null) {
return List.of();
}
return numbers.stream()
.filter(n -> n % 2 == 0)
.map(n -> n * n)
.collect(Collectors.toList());
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
