The of() method of ValueRange class helps us to Obtains value range based on parameters passed to it.
There are three types of of() methods based on parameters passed to it.
- of(long min, long max): This method help us to get a fixed value range where the minimum and maximum values are fixed.
Syntax:
public static ValueRange of(long min, long max)
Parameters: This method accepts two parameters:- min which is the minimum value
- max which is the maximum value
Java // Java program to demonstrate // ValueRange.of(long min, long max) method import java.time.temporal.ValueRange; public class GFG { public static void main(String[] args) { // create ValueRange using // of(long min, long max) ValueRange vRange = ValueRange.of(0, 66666); // print results System.out.println("ValueRange: " + vRange.toString()); } }
Output:ValueRange: 0 - 66666
- of(long min, long maxSmallest, long maxLargest): This method helps us to get a variable value range where the minimum value is fixed and the maximum value may vary.
Syntax:
public static ValueRange of(long min, long maxSmallest, long maxLargest)Parameters: This method accepts three parameters:- min which is the minimum value,
- maxSmallest which is the smallest maximum value
- maxLargest which is the largest maximum value.
Java // Java program to demonstrate // of(long, long, long) method import java.time.temporal.ValueRange; public class GFG { public static void main(String[] args) { // create ValueRange using // of(long min, long maxSmallest, long maxLargest) ValueRange vRange = ValueRange.of(0, 230, 500); // print results System.out.println("ValueRange: " + vRange.toString()); } }
Output:ValueRange: 0 - 230/500
- of(long minSmallest, long minLargest, long maxSmallest, long maxLargest): This method helps us to get a fully variable value range where both the minimum and maximum value may vary.
Syntax:
public static ValueRange of(long minSmallest, long minLargest, long maxSmallest, long maxLargest)Parameters: This method accepts four parameters:- minSmallest which is the smallest minimum value
- minLargest which is the largest minimum value,
- maxSmallest which is the smallest maximum value
- maxLargest which is the largest maximum value.
Java // Java program to demonstrate // of(long, long, long, long) method import java.time.temporal.ValueRange; public class GFG { public static void main(String[] args) { // create ValueRange using // of(long minSmallest, long minLargest, // long maxSmallest, long maxLargest) ValueRange vRange = ValueRange.of(0, 1, 500, 1000); // print results System.out.println("ValueRange: " + vRange.toString()); } }
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ValueRange.htmlValueRange: 0/1 - 500/1000