Open In App

ValueRange checkValidValue() method in Java with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

The checkValidValue() method of ValueRange class is used to check that the value passed as parameter is valid. The field passed as a parameter is only used to improve the error message. This method checks that the passed value lies in ValueRange or not.

Syntax:

public long checkValidValue(long value, TemporalField field)

Parameters: This method accepts two parameters:

  • value which is the value to check and
  • scope which is the field being checked.

Return value: This method returns the value that was passed in.

Below programs illustrate the ValueRange.checkValidValue() method:
Program 1:




// Java program to demonstrate
// ValueRange.checkValidValue() method
  
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create ValueRange object
        ValueRange vRange = ValueRange.of(1, 10000);
  
        // check value 4999 in range or not
        long value1 = vRange.checkValidValue(4999, null);
  
        // print
        System.out.println("Value passed :" + value1);
    }
}


Output:

Value passed :4999

Program 2:




// Java program to demonstrate
// ValueRange.checkValidValue() method
  
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create ValueRange object
        ValueRange vRange = ValueRange.of(1111, 99999);
  
        // check value 6666 in range or not
        long value1 = vRange.checkValidValue(6666, null);
  
        // print
        System.out.println("Value passed :" + value1);
    }
}


Output:

Value passed :6666

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ValueRange.html#checkValidValue(long, java.time.temporal.TemporalField)



Last Updated : 29 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads