ValueRange isValidValue() method in Java with Examples
Last Updated :
29 Jan, 2020
The isValidValue() method of ValueRange class is used to check if the value which is passed as parameter is within the valid range. This method validates that the value is within the stored range of values.
Syntax:
public boolean isValidValue(long value)
Parameters: This method accepts value which is the value to check.
Return value: This method returns true if the value is valid.
Below programs illustrate the ValueRange.isValidValue() 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( "2020-10-06T08:21:14" );
ValueRange vR
= l1.range(ChronoField.DAY_OF_MONTH);
boolean response = vR.isValidValue( 12 );
System.out.println( "isValidValue: "
+ response);
}
}
|
Output:
isValidValue: 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.isValidValue( 12 );
System.out.println( "isValidValue: "
+ response);
}
}
|
Output:
isValidValue: false
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ValueRange.html#isValidValue(long)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...