Dark theme | Light theme

June 14, 2010

Groovy Goodness: Getting Head And Tail From an Array of Objects

We could already use the head() and tail() methods on Collection objects in Groovy, but in Groovy 1.7.3 we can use them on Object arrays as well.

String[] stringArray = ['Groovy', 'Grails', 'Spock']

assert 'Groovy' == stringArray.head()
assert ['Grails', 'Spock'] == stringArray.tail()
assert 'Groovy' == stringArray.first()
assert 'Spock' == stringArray.last()