ChronoField checkValidIntValue() method in Java with Examples
The checkValidIntValue() method of ChronoField enum is used to check that the value passed as parameter is valid for ChronoField constant or not and value fits in an integer or not.
Syntax:
public int checkValidIntValue(long value)
Parameters: This method accepts value which is the value to check.
Return value: This method returns the value that was passed in.
Below programs illustrate the ChronoField.checkValidIntValue() method:
Program 1:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "HOUR_OF_DAY" );
int validInt
= chronoField.checkValidIntValue( 21 );
System.out.println( "Value passed :"
+ validInt);
}
}
|
Program 2:
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
ChronoField chronoField
= ChronoField.valueOf( "YEAR_OF_ERA" );
int validInt
= chronoField.checkValidIntValue( 2021 );
System.out.println( "Value passed :"
+ validInt);
}
}
|
Output:
Value passed :2021
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#checkValidIntValue(long)
Last Updated :
29 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...