The isSupported(TemporalField) method of YearMonth class is used to check if the specified field is supported by YearMonth class or not means using this method we can check if this YearMonth object can be queried for the specified field.
The supported fields of ChronoField are:
- MONTH_OF_YEAR
- PROLEPTIC_MONTH
- YEAR_OF_ERA
- YEAR
- ERA
All other ChronoField instances will return false.
Syntax:
public boolean isSupported(TemporalField field)
Parameters: This method accepts only one parameter field which represents the field to check.
Return Value: This method returns the boolean value true if the field is supported on this YearMonth, false if not.
Below programs illustrate the isSupported(TemporalField) method:
Program 1:
// Java program to demonstrate // YearMonth.isSupported(TemporalField) method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // Create a YearMonth object YearMonth thisYearMonth = YearMonth.of(2017, 8); // print instance System.out.println("YearMonth :" + thisYearMonth); // apply isSupported() method boolean value = thisYearMonth.isSupported( ChronoField.PROLEPTIC_MONTH); // print result System.out.println("PROLEPTIC_MONTH Field is supported by YearMonth class: " + value); } } |
YearMonth :2017-08 PROLEPTIC_MONTH Field is supported by YearMonth class: true
Program 2:
// Java program to demonstrate // YearMonth.isSupported(TemporalField) method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // Create a YearMonth object YearMonth thisYearMonth = YearMonth.of(2017, 8); // print instance System.out.println("YearMonth :" + thisYearMonth); // apply isSupported() method boolean value = thisYearMonth.isSupported( ChronoField.HOUR_OF_DAY); // print result System.out.println("HOUR_OF_DAY Field is supported by YearMonth class: " + value); } } |
YearMonth :2017-08 HOUR_OF_DAY Field is supported by YearMonth class: false
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- YearMonth of(int, int) method in Java with Examples
- YearMonth with() Method in Java with Examples
- YearMonth now() method in Java with Examples
- YearMonth get() method in Java with Examples
- YearMonth until() Method in Java with Examples
- YearMonth plusMonths() method in Java with Examples
- YearMonth lengthOfYear() method in Java with Examples
- YearMonth plusYears() method in Java with Examples
- YearMonth getLong() method in Java with Examples
- YearMonth now(clock) method in Java with Examples
- YearMonth minusMonths() method in Java with Examples
- YearMonth range() method in Java with Examples
- YearMonth of(int, Month) method in Java with Examples
- YearMonth query() Method in Java with Examples
- YearMonth plus(TemporalAmount) method in Java with Examples
- YearMonth isAfter() method in Java with Examples
- YearMonth withMonth() method in Java with Examples
- YearMonth withYear() method in Java with Examples
- YearMonth isBefore() method in Java with Examples
- YearMonth isLeapYear() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh

