The isSupported() method is a built-in method of the Month ENUM which is used to check if the specified field is supported or not. This method accepts a fields as a parameter and returns true or false based on whether the field is supported or not.
Syntax:
public boolean isSupported(TemporalField field)
Parameters: This method accepts a single parameter field, which is to be checked if it is supported or not.
Return Value: This method returns a boolean value True if the field is supported otherwise it returns False.
Below programs illustrate the above method:
Program 1:
import java.time.*; import java.time.Month; import java.time.temporal.ChronoField; class monthEnum { public static void main(String[] args) { // Create a month instance Month month = Month.of( 5 ); // check if the field is valid if (month.isSupported(ChronoField.MONTH_OF_YEAR)) System.out.println( "This field is supported!" ); else System.out.println( "This field is not supported!" ); } } |
This field is supported!
Program 2:
import java.time.*; import java.time.Month; import java.time.temporal.ChronoField; class monthEnum { public static void main(String[] args) { // Create a month instance Month month = Month.of( 5 ); // check if the field is valid if (month.isSupported(ChronoField.DAY_OF_WEEK)) System.out.println( "This field is supported!" ); else System.out.println( "This field is not supported!" ); } } |
This field is not supported!
Reference: https://www.tutorialspoint.com/javatime/javatime_month_issupported.htm