Wednesday, July 8, 2026
HomeLanguagesJavaValueRange checkValidIntValue() method in Java with Examples

ValueRange checkValidIntValue() method in Java with Examples

The checkValidIntValue() method of ValueRange class is used to check that the value passed as parameter is valid and fits in an int. This method validates that the value passed as a parameter is within the valid range of values or not. For this method, it is important that the value return by method fits in it or not. The field passed as a parameter is only used to improve the error message. Syntax:

public int checkValidIntValue(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, may be null.

Return value: This method returns the value that was passed in. Below programs illustrate the ValueRange.checkValidIntValue() method: Program 1: 

Java




// Java program to demonstrate
// ValueRange.checkValidIntValue() 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 500 in range or not
        int value1 = vRange.checkValidIntValue(500, null);
 
        // print
        System.out.println("Value passed :" + value1);
    }
}


Output:

Value passed :500

Program 2: 

Java




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


Output:

Value passed :44444

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12016 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12111 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6978 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS