diff options
author | Tim Yates <tyates@picr.man.ac.uk> | 2013-09-02 12:57:29 +0100 |
---|---|---|
committer | Tim Yates <tyates@picr.man.ac.uk> | 2013-09-02 12:57:29 +0100 |
commit | 68f26804c54280ad86ce639ae428fdf3b670de8b (patch) | |
tree | f6f4fc6bf2215ff0c4f2704aecdc764a24a636a9 /groovy.html.markdown | |
parent | 39b96dd2db1de1c8d31ef6ce1c05543e7f690659 (diff) |
Added a few more examples for List manipulation
Diffstat (limited to 'groovy.html.markdown')
-rw-r--r-- | groovy.html.markdown | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/groovy.html.markdown b/groovy.html.markdown index e440ef00..63cef76b 100644 --- a/groovy.html.markdown +++ b/groovy.html.markdown @@ -54,15 +54,26 @@ println x //Creating an empty list def technologies = [] -//Add an element to the list -technologies << "Groovy" +/*** Adding a elements to the list ***/ + +// As with Java technologies.add("Grails") + +// Left shift adds, and returns the list +technologies << "Groovy" + +// Add multiple elements technologies.addAll(["Gradle","Griffon"]) -//Remove an element from the list +/*** Removing elements from the list ***/ + +// As with Java technologies.remove("Griffon") -//Iterate over elements of a list +// Subtraction works also +technologies = technologies - 'Grails' + +// Iterate over elements of a list technologies.each { println "Technology: $it"} technologies.eachWithIndex { it, i -> println "$i: $it"} |