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
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.