- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MonthDay isAfter() Method in Java
It can be checked if a particular MonthDay is after the other MonthDay in a timeline using the isAfter() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object that is to be compared. It returns true if the MonthDay object is after the other MonthDay object and false otherwise.
A program that demonstrates this is given as follows
Example
import java.time.*; public class Main { public static void main(String[] args) { MonthDay md1 = MonthDay.parse("--02-25"); MonthDay md2 = MonthDay.parse("--02-21"); System.out.println("The MonthDay md1 is: " + md1); System.out.println("The MonthDay md2 is: " + md2); boolean flag = md1.isAfter(md2); if(flag) System.out.println("
MonthDay object md1 is after MonthDay object md2"); else System.out.println("
MonthDay object md1 is before MonthDay object md2"); } }
output
The MonthDay md1 is: --02-25 The MonthDay md2 is: --02-21 MonthDay object md1 is after MonthDay object md2
Now let us understand the above program.
The two MonthDay objects md1 and md2 are displayed. It is checked if the MonthDay object md1 is after the MonthDay object md2 in the timeline using the isAfter() method. The returned value is displayed using an if statement. A code snippet that demonstrates this is as follows:
MonthDay md1 = MonthDay.parse("--02-25"); MonthDay md2 = MonthDay.parse("--02-21"); System.out.println("The MonthDay md1 is: " + md1); System.out.println("The MonthDay md2 is: " + md2); boolean flag = md1.isAfter(md2); if(flag) System.out.println("
MonthDay object md1 is after MonthDay object md2"); else System.out.println("
MonthDay object md1 is before MonthDay object md2");
Advertisements