ValueRange getSmallestMaximum() method in Java with Examples
Last Updated :
27 Apr, 2023
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
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args)
{
LocalDateTime l1
= LocalDateTime.parse( "2018-02-06T19:21:12" );
ValueRange vR = l1.range(ChronoField.DAY_OF_MONTH);
long sMax = vR.getSmallestMaximum();
System.out.println( "Smallest Maximum "
+ "for DAY_OF_MONTH: " + sMax);
}
}
|
Output:
Smallest Maximum for DAY_OF_MONTH: 28
Program 2:
Java
import java.time.temporal.ValueRange;
public class GFG {
public static void main(String[] args)
{
ValueRange vRange = ValueRange.of( 1111 , 99999 );
long smax = vRange.getSmallestMaximum();
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...