ValueRange isValidIntValue() method in Java with Examples
The isValidIntValue() method of ValueRange class is used to check if the value which is passed as parameter is within the valid range. This method also validates that all values in the range fit in an int.
Syntax:
public boolean isValidIntValue(long value)
Parameters: This method accepts value which is the value to check.
Return value: This method returns true if the value is valid and fits in an int.
Below programs illustrate the ValueRange.isValidIntValue() method:
Program 1:
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args)
{
LocalDateTime l1
= LocalDateTime
.parse( "2018-12-06T19:21:12" );
ValueRange vR
= l1.range(ChronoField.DAY_OF_MONTH);
boolean response = vR.isValidIntValue( 30 );
System.out.println( "isValidIntValue: "
+ response);
}
}
|
Output:
isValidIntValue: true
Program 2:
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args)
{
ValueRange vRange = ValueRange.of( 1111 , 66666 );
boolean response = vRange.isValidIntValue( 333 );
System.out.println( "isValidIntValue: "
+ response);
}
}
|
Output:
isValidIntValue: false
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ValueRange.html#isValidIntValue()
Last Updated :
29 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...