- 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
Duration equals() method in Java
The equality of two durations can be determined using the equals() method in the Duration class in Java. This method requires a single parameter i.e. the duration to be compared. Also, it returns true if both the durations are equal and false otherwise.
A program that demonstrates this is given as follows −
Example
import java.time.Duration; public class GFG { public static void main(String[] args) { Duration d1 = Duration.ofDays(1); Duration d2 = Duration.ofHours(24); boolean flag = d1.equals(d2); if(flag) System.out.println("The durations are equal"); else System.out.println("The durations are not equal"); } }
Output
The durations are equal
Now let us understand the above program.
The two durations are compared using the method equals() and the returned value is stored in the flag. Then it is displayed whether the durations are equal or not. A code snippet that demonstrates this is as follows −
Duration d1 = Duration.ofDays(1); Duration d2 = Duration.ofHours(24); boolean flag = d1.equals(d2); if(flag) System.out.println("The durations are equal"); else System.out.println("The durations are not equal");
- Related Articles
- Duration minus() method in Java
- Duration plus() method in Java
- Duration dividedBy() method in Java
- Duration multipliedBy() method in Java
- Duration toDays() method in Java
- Duration plusMillis() method in Java
- Duration plusSeconds() method in Java
- Duration plusMinutes() method in Java
- Duration plusHours() method in Java
- Duration minusHours() method in Java
- Duration minusDays() method in Java
- Duration toMillis() method in Java
- Duration toNanos() method in Java
- Duration getSeconds() method in Java
- Duration getUnits() method in Java

Advertisements