The getSmallestMaximum() method of ValueRange class is used to get the smallest possible maximum value that the valueRange can take. For example, ChronoField DAY_OF_MONTH always lies between 28 and 31 days. The smallest maximum is therefore 28.
Syntax:
public long getSmallestMaximum()
Parameters: This method accepts nothing.
Return value: This method returns the smallest possible maximum value for this valueRange.
Below programs illustrate the ValueRange.getSmallestMaximum() method:
Program 1:
// Java program to demonstrate
// ValueRange.getSmallestMaximum() 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("2018-02-06T19:21:12");
// Get ValueRange object
ValueRange vR = l1.range(ChronoField.DAY_OF_MONTH);
// apply getSmallestMaximum()
long sMax = vR.getSmallestMaximum();
// print results
System.out.println("Smallest Maximum "
+ "for DAY_OF_MONTH: " + sMax);
}
}
Output:
Smallest Maximum for DAY_OF_MONTH: 28
Program 2:
// Java program to demonstrate
// ValueRange.getSmallestMaximum() method
import java.time.temporal.ValueRange;
public class GFG {
// Main driver method
public static void main(String[] args)
{
// Creating ValueRange object
ValueRange vRange = ValueRange.of(1111, 99999);
// get smallest Maximum value
long smax = vRange.getSmallestMaximum();
// print results
System.out.println("smallest maximum : " + smax);
}
}
Output:
smallest maximum : 99999
Example:
import java.io.*;
import java.time.LocalTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args) {
LocalTime time = LocalTime.now();
ValueRange range = time.range(ChronoField.MINUTE_OF_HOUR);
long smallestMax = range.getSmallestMaximum();
System.out.println("The smallest maximum value in the range is: " + smallestMax);
}
}
output :
The smallest maximum value in the range is: 59