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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Smallest Maximum for DAY_OF_MONTH: 28

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// ValueRange.getSmallestMaximum() method
  
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create ValueRange object
        ValueRange vRange = ValueRange.of(1111, 99999);
  
        // get smallest Maximum value
        long smax = vRange.getSmallestMaximum();
  
        // print results
        System.out.println("smallest maximum : "
                           + smax);
    }
}

chevron_right


Output:

smallest maximum : 99999

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

java-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.