java.time.temporal.ValueRange Class in Java
Last Updated :
28 Mar, 2021
The ValueRange Class captures the valid range of the values of TemporalField instances. Given class provides the minimum and maximum values of the range.
Note: It’s possible that there might be invalid values within the outer range. For example, a field may have valid values of 1, 2, 3, 6, 7, thus have a range of ‘1-7’, despite the fact that values 4 and 5 are not valid.
Class declaration:
public final class ValueRange
extends Object
implements Serializable
ValueRange Class inherits following methods from class java.lang.Object:
- clone()
- finalize()
- getClass()
- notify()
- notifyAll()
- wait()
Methods of ValueRange Class:
Example 1:
Java
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args)
{
ValueRange vRange = ValueRange.of( 5555 , 1000000 );
long minVal = vRange.getMinimum();
long maxVal = vRange.getMaximum();
System.out.println( "Minimum value is: " + minVal);
System.out.println( "Maximum value is: " + maxVal);
}
}
|
Output
Minimum value is: 5555
Maximum value is: 1000000
Example 2:
Java
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args)
{
ValueRange vRange = ValueRange.of( 1 , 10000 );
long value1 = vRange.checkValidValue( 6001 , null );
System.out.println( "Value passed: " + value1);
}
}
|
Output
Value passed: 6001
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...