Sunday, November 17, 2024
Google search engine
HomeLanguagesJavaYear isSupported(TemporalField) Method in Java with Examples

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.*;
 
// Class
public 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.*;
 
// Class
public 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 

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

Most Popular

Recent Comments