 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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");Advertisements
 