ReePrime
πŸ’‘ Java Interview Question:

Hosted by Dailymotion. For legal issues report at the Copyright Center, report us on DMC, or use the Instant Removal tool.

πŸ’‘ Java Interview Question:

A
aswin_zsw880

1 Views β€’ Feb 09, 2026

Description



πŸ‘‰ How can you find leap years using the Java Stream API?
This is a popular Java interview question to test your understanding of Streams and functional programming.
Here’s the clean Java code πŸ‘‡
import java.util.List;
import java.util.stream.Collectors;
public class LeapYearStream {
public static void main(String[] args) {
List years = List.of(1999, 2000, 2004, 2010, 2020, 2023);
List leapYears = years.stream()
.filter(y -> (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
.collect(Collectors.toList());
System.out.println(leapYears);
}
}
🎯 Explanation:
Stream processes a list of years one by one
filter() applies the leap year condition
A leap year is divisible by 4 and not by 100 OR divisible by 400
collect() gathers all leap years into a list
Clean, readable, and interview-friendly
βœ… Perfect for:
βœ”οΈ Java Interviews
βœ”οΈ Java 8+ Stream API Learners
βœ”οΈ Backend Developers
βœ”οΈ Java + Spring Boot Developers
πŸ‘‰ Save this post for Java revision
πŸ‘‰ Follow @ashokitschool for more Java + SQL + Full Stack content
#JavaInterviewQuestions #JavaStreams #LeapYear #StreamAPI #BackendDeveloper #JavaDeveloper #SpringBoot #AshokIT #CodingInterview #LearnJava #ProgrammingTips #JobReadySkills #FullStackDeveloper