Groovy - Range getTo() method
getTo() method returns the upper value of this Range.
Syntax
Comparable getTo()
Parameters
NA
Return Value
Returns the upper value of the range.
Example - Getting upper value of range of numbers
Following is an example of the usage of getTo() method.
Example.groovy
class Example {
static void main(String[] args) {
// range of numbers
def array = 1..10;
println(array.getTo());
}
}
Output
When we run the above program, we will get the following result −
10
Example - Getting upper value of range of characters
Following is an example of the usage of getTo() method.
Example.groovy
class Example {
static void main(String[] args) {
// range of characters
def array = 'a'..'z';
println(array.getTo());
}
}
Output
When we run the above program, we will get the following result −
z
Example - Getting upper value of range of special characters
Following is an example of the usage of getTo() method.
Example.groovy
class Example {
static void main(String[] args) {
// range of special characters
def array = '&'..'!';
println(array.getTo());
}
}
Output
When we run the above program, we will get the following result −
&
groovy_ranges.htm
Advertisements