Skip to content
Related Articles

Related Articles

MonthDay isSupported() Method in Java with Examples
  • Last Updated : 18 Jan, 2019

isSupported() method of the MonthDay class used to Check if the specified field is supported by MonthDay class or not means using this method we can check if this MonthDay can be queried for the specified field.
The supported fields of ChronoField are:

  • MONTH_OF_YEAR
  • YEAR

All other ChronoField instances will return false.

Syntax:

public boolean isSupported(TemporalField field)

Parameters: This method accepts one parameter field which is the field to check.

Return value: This method returns returns boolean value true if the field is supported on this MonthDay, false if not.



Below programs illustrate the isSupported() method:
Program 1:




// Java program to demonstrate
// MonthDay.isSupported() method
  
import java.time.*;
import java.time.temporal.ChronoField;
  
public class GFG {
    public static void main(String[] args)
    {
        // create a MonthDay object
        MonthDay month = MonthDay.parse("--10-12");
  
        // apply isSupported() method
        boolean value
            = month.isSupported(
                ChronoField.MONTH_OF_YEAR);
  
        // print result
        System.out.println("MONTH_OF_YEAR Field is supported: "
                           + value);
    }
}
Output:
MONTH_OF_YEAR Field is supported: true

Program 2:




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

References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.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 :