Wednesday, July 3, 2024
HomeLanguagesJavaValueRange getSmallestMaximum() method in Java with Examples

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

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments