Skip to content
Related Articles

Related Articles

Year isSupported(TemporalField) Method in Java with Examples
  • Last Updated : 24 Jul, 2019

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:</strong 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 Year, false if not.

Below programs illustrate the isSupported(TemporalField) method:

Program 1:




// Java program to demonstrate
// Year.isSupported(TemporalField) method
  
import java.time.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create a Year object
        Year year = Year.of(2019);
  
        // print instance
        System.out.println("Year :"
                           + year);
  
        // apply isSupported() method
        boolean value
            = year.isSupported(
                ChronoField.YEAR_OF_ERA);
  
        // print 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 2:




// Java program to demonstrate
// Year.isSupported(TemporalField) method
  
import java.time.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create a Year object
        Year year = Year.of(2022);
  
        // print instance
        System.out.println("Year :"
                           + year);
  
        // apply isSupported() method
        boolean value
            = year.isSupported(
                ChronoField.MILLI_OF_SECOND);
  
        // print result
        System.out.println("MiliSecond Field is supported: "
                           + value);
    }
}
Output:
Year :2022
MiliSecond Field is supported: false

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

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :