O'Reilly logo

Programming Groovy 2 by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Other Extensions

The GDK extensions go beyond the Object class. Several other JDK classes and interfaces have been enhanced in the GDK. Again, the list is vast and we’ll look at only a subset of extensions in this section. These are the extensions we’re likely to put to regular use.

Array Extensions

We can use the Range object as an index on all the array types (for the syntax for creating arrays, see Different Syntax for Creating Primitive Arrays), such as int[], double[], and char[]. Here’s how we can access contiguous values in an int array using the range of index:

ExploringGDK/Array.groovy
 
int​​[]​ arr = [1, 2, 3, 4, 5, 6]
 
 
println arr[2..4]

The output shows the values in the given range:

 
[3, 4, 5]

We’re already familiar with a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required