YearMonth compareTo(YearMonth other)
compares this year-month to another year-month.
compareTo
has the following syntax.
public int compareTo(YearMonth other)
The following example shows how to use compareTo
.
import java.time.YearMonth; 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.