Duration compareTo(Duration) method in Java with Examples
The compareTo(Duration) method of Duration Class in java.time package is used to compare this duration with the duration passed as the parameter.
public int compareTo(Duration otherDuration)
Parameters: This method accepts a parameter otherDuration which is the duration to which this duration will be compared to.
Return Value: This method returns an int value where negative value means that otherDuration is larger than this value, zero means otherDuration is equal to this duration, and positive value means this duration is larger than the otherDuration.
Below examples illustrate the Duration.compareTo() method:
Reference: Oracle Doc