What is Range.getMinimum() in Java?
Overview
getMinimum() is an instance method of the Range class that is used to get the minimum value in the range.
How to import Range
We can find the definition of Range in the Apache Commons Lang package, which we can add to the Maven project by adding the following dependency to the pom.xml file:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the
commons-langpackage, refer to the Maven Repository.
We can import the Range class as follows:
import org.apache.commons.lang3.Range;
Syntax
public T getMinimum()
Parameters
This method has no parameters.
Return value
The getMinimum() method returns the minimum value in the range.
Code
import org.apache.commons.lang3.Range;public class Main{public static void main(String[] args) {int fromValue = 100;int toValue = 200;Range<Integer> range = Range.between(fromValue, toValue);System.out.printf("Range object - %s\n", range);System.out.println("Minimum value - " + range.getMinimum());}}
Explanation
- In line
3, we define the Main class. - In line
5, we define the main method. - In line
6, we define the minimum/fromValueof the range. - In line
7, we define the maximum/toValue of the range. - In line
8, we use thebetweenmethod to get theRangeobject. - In line
9, we print theRangeobject. - In line
10, we use thegetMinimum()method to get the minimum value of the range.
Output
The output of the code will be as follows:
Range object - [100..200]
Minimum value - 100