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
More from User
01:31
Python Interview Question:
aswin_zsw880
02:58
Java Interview Question:
aswin_zsw880
01:52
π‘ Java Interview Question:
aswin_zsw880
Related Videos
00:27
[PDF] Java Interview Notes: 700 Java Interview Questions Answered Full Online
LiliaFiggins
00:30
PDF Java Interview Notes 700 Java Interview Questions Answered Read Online
Teddieorange
00:23
PDF Java Interview Questions Java Programming Certification Review Download Online
Keep
06:08
Java Interview Question
ApanaBhau
01:10
Java Multithreading Interview Questions
Ellen gomez
00:25
java interview questions
vansh nath