Year isSupported(TemporalField) Method in Java with Examples

The isSupported(TemporalField) method of Year class is used to check if the specified field is supported by Year class or not means using this method we can check if this Year object can be queried for the specified field.
The supported fields of ChronoField are:Â
- YEAR_OF_ERA
- YEAR
- ERA
All other ChronoField instances will return false.
Syntax:Â Â
public boolean isSupported(TemporalField field)
Parameters: Field which represents the field to check.
Return Value: Boolean value true if the field is supported on this Year, false if not.
Below programs illustrate the isSupported(TemporalField) method:
Program 1:Â Â
Java
// Java program to demonstrate// Year.isSupported(TemporalField) methodÂ
import java.time.*;import java.time.temporal.*;Â
// Classpublic class GFG {Â
    // Main driver method    public static void main(String[] args)    {        // Creating a Year object        Year year = Year.of(2019);Â
        // Printing instance        System.out.println("Year :" + year);Â
        // apply isSupported() method        boolean value            = year.isSupported(ChronoField.YEAR_OF_ERA);Â
        // Printing result        System.out.println(            "YEAR_OF_ERA Field is supported by Year class: "            + value);    }} |
Output
Year :2019 YEAR_OF_ERA Field is supported by Year class: true
Program 2A:Â
Java
// Java program to demonstrate// Year.isSupported(TemporalField) methodÂ
import java.time.*;import java.time.temporal.*;Â
// Classpublic class GFG {Â
    // Main driver method    public static void main(String[] args)    {        // Creating a Year object        Year year = Year.of(2022);Â
        // Printing instance        System.out.println("Year :" + year);Â
        // apply isSupported() method        boolean value            = year.isSupported(ChronoField.MILLI_OF_SECOND);Â
        // Printing result        System.out.println(            "MilliSecond Field is supported: " + value);    }} |
Output
Year :2022 MilliSecond Field is supported: false
Program 2B:
Java
import java.io.*;import java.time.LocalDate;import java.time.temporal.ChronoField;Â
public class GFG {       public static void main(String[] args)    {        // Creating object of class        LocalDate date = LocalDate.of(2023, 4, 17);Â
        boolean isSupportedYear            = date.isSupported(ChronoField.YEAR);               System.out.println("Is year supported? "                           + isSupportedYear);Â
        boolean isSupportedDayOfWeek            = date.isSupported(ChronoField.DAY_OF_WEEK);               System.out.println("Is day of week supported? "                           + isSupportedDayOfWeek);    }} |
Output:
Is year supported? true Is day of week supported? true



