Saturday, June 13, 2026
HomeLanguagesJavaYearMonth isSupported(TemporalField) method in Java with Examples

YearMonth isSupported(TemporalField) method in Java with Examples

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


Output:

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


Output:

YearMonth :2017-08
HOUR_OF_DAY Field is supported by YearMonth class: false

References:
https://docs.oracle.com/javase/10/docs/api/java/time/YearMonth.html#isSupported(java.time.temporal.TemporalField)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS