java.time.Duration.equals() Method Example



Description

The java.time.Duration.equals() method checks if this duration is equal to the specified Duration.

Declaration

Following is the declaration for java.time.Duration.equals() method.

public int equals(Duration otherDuration)

Parameters

otherDuration − the other duration, null returns false.

Return Value

true if the other duration is equal to this one.

Example

The following example shows the usage of java.time.Duration.equals() method.

package com.tutorialspoint;

import java.time.Duration;
import java.time.LocalTime;

public class DurationDemo {
   public static void main(String[] args) {

      Duration duration = Duration.between(LocalTime.NOON,LocalTime.MAX); 
      Duration duration1 = Duration.between(LocalTime.NOON,LocalTime.MIN); 
      System.out.println(duration.equals(duration1));
   }
}

Let us compile and run the above program, this will produce the following result −

false
Advertisements