From 68f26804c54280ad86ce639ae428fdf3b670de8b Mon Sep 17 00:00:00 2001 From: Tim Yates Date: Mon, 2 Sep 2013 12:57:29 +0100 Subject: Added a few more examples for List manipulation --- groovy.html.markdown | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'groovy.html.markdown') 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"} -- cgit v1.2.3