The is()
is a Range
class in Java - which is used to obtain a Range
object using the specified element as both the minimum and maximum in the range.
The class of the element has to implement the
Comparable
interface.
Range
The definition of Range
can be found 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-lang package, refer to the Maven Repository.
You can import the Range
class as follows:
import org.apache.commons.lang3.Range;
public static <T extends Comparable<T>> Range<T> is(final T element)
final T element
: The element to use as the maximum and minimum value.This method returns a Range
object.
import org.apache.commons.lang3.Range;public class Main{public static void main(String[] args) {int element = 100;Range<Integer> range = Range.is(element);System.out.printf("Range object - %s\n", range);}}
Main
class.main
method.Range
object.Range
object using the is()
method.The output of the code will be as follows:
Range object - [100..100]