Groovy Collections offer us a class in addition to Java Collections, called Range. Range is a subclass of java.util.List and is used for creating lists of sequential values. Some ranges can be: 1..3 a..d Notice that we use the .. operator to create a range. However ranges are not limited to numbers and characters. Any object which implements the methods compareTo(), next(), and previous() can be used in a Range. Ranges typically have a left and right border, and they can be either inclusive (containing border elements) or exclusive (sans the right border element). Ranges are usually used to extract a subset of elements from a list or used in switch statements to match a range of cases together. The code below is self explanatory: //A simple Groovy Range def inclusiveRange = 1..10 println 'The size of inclusiveRange is: ' + inclusiveRange.size() //This range does not include the right border element def exclusiveRange = 1.. 0} Output from running the above program: The size of ...
Write Awesome User Manuals and Tutorials for Software Products