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:
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
import java.time.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
Year year = Year.of( 2019 );
System.out.println( "Year :" + year);
boolean value
= year.isSupported(ChronoField.YEAR_OF_ERA);
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
import java.time.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
Year year = Year.of( 2022 );
System.out.println( "Year :" + year);
boolean value
= year.isSupported(ChronoField.MILLI_OF_SECOND);
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)
{
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
Last Updated :
01 May, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...