Saturday, October 18, 2025
HomeLanguagesJavaValueRange isValidValue() method in Java with Examples

ValueRange isValidValue() method in Java with Examples

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:




// Java program to demonstrate
// ValueRange.isValidValue() method
  
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create LocalDateTime
        LocalDateTime l1
            = LocalDateTime
                  .parse("2020-10-06T08:21:14");
  
        // Get ValueRange object
        ValueRange vR
            = l1.range(ChronoField.DAY_OF_MONTH);
  
        // apply isValidValue()
        boolean response = vR.isValidValue(12);
  
        // print results
        System.out.println("isValidValue: "
                           + response);
    }
}


Output:

isValidValue: true

Program 2:




// Java program to demonstrate
// ValueRange.isValidValue() method
  
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create ValueRange object
        ValueRange vRange = ValueRange.of(1111, 66666);
  
        // apply isValidValue()
        boolean response = vRange.isValidValue(12);
  
        // print results
        System.out.println("isValidValue: "
                           + response);
    }
}


Output:

isValidValue: false

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS