YearMonth compareTo(YearMonth other) example
Description
YearMonth compareTo(YearMonth other)
compares this year-month to another year-month.
Syntax
compareTo
has the following syntax.
public int compareTo(YearMonth other)
Example
The following example shows how to use compareTo
.
import java.time.YearMonth;
/*w ww. java 2 s . c om*/
public class Main {
public static void main(String[] args) {
YearMonth y = YearMonth.now();
System.out.println(y.compareTo(YearMonth.now()));
}
}
The code above generates the following result.