Groovy snippet – Collection

複製陣列裡某個區段的元素成為新的陣列:

String groovyIntro = "Groovy is an agile and dynamic language for the Java Virtual Machine."
String[] words = groovyIntro.split(" ")
assert ['an', 'agile', 'and', 'dynamic', 'language'] == words[2..6]
assert 'Machine.' == words[-1]
assert ['Machine.', 'Virtual', 'Java'] == words[-1..-3]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s