ValueRange getSmallestMaximum() method in Java with Examples

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
// 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
// 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:
Java
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



