Friday, July 3, 2026
HomeLanguagesJavaMonth isSupported() method in Java

Month isSupported() method in Java

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!");
    }
}


Output:

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!");
    }
}


Output:

This field is not supported!

Reference: https://www.tutorialspoint.com/javatime/javatime_month_issupported.htm

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6966 POSTS0 COMMENTS