Range operator '..' defines a list of sequential values.
groovy:000> x = 1..10 ===> 1..10 groovy:000> x ===> 1..10 groovy:000> x[0] ===> 1 groovy:000> x[5] ===> 6 groovy:000> x.size() ===> 10 groovy:000> x.from ===> 1 groovy:000> x.to ===> 10 groovy:000> x.last() ===> 10
HelloWorld.groovy
def integers = 1..20 println "Element at index 5 : " + integers[5] println "Size of integers list : " + integers.size() println "Is integers instance of list : " + (integers instanceof List) println "Reverse of elements : " + integers.reverse() println "Is list contains element 15 ? " + integers.contains(15)
Output
def integers = 1..20 println "Element at index 5 : " + integers[5] println "Size of integers list : " + integers.size() println "Is integers instance of list : " + (integers instanceof List) println "Reverse of elements : " + integers.reverse() println "Is list contains element 15 ? " + integers.contains(15)
No comments:
Post a Comment