Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Groovy range


May 14, 2021 Groovy



A range is shorthand for a specified sequence of values. The range is represented by the first and last values in the sequence, and Range can be included or excluded. The include range includes all values from the first to the last, while the exclusive range includes all values except the last. Here are some examples of sample text -

  • 1..10 - An example that contains a range
  • 1 .. slt;10 - an example of an exclusive range
  • 'a'..' x' - The range can also consist of characters
  • 10...1 - Ranges can also be arranged in descending order
  • 'x'..' a' - The range can also be composed of characters and arranged in descending order.

Here are the various methods available for scope.

Serial number Method and description
1 contains()

Check if the range contains a specific value

2 get()

Returns the element at the specified location in this range.

3 getFrom()

Get the lower limit for this range.

4 getTo()

Get the upper limit for this range.

5 isReverse()

This is a reverse range, a reverse iteration

6 size()

Returns the number of elements in this range.

7 subList()

Returns a view of this range section between this specified fromIndex (included) and toIndex (excluded).