summaryrefslogtreecommitdiffhomepage
path: root/groovy.html.markdown
diff options
context:
space:
mode:
authorTim Yates <tyates@picr.man.ac.uk>2013-09-02 13:02:53 +0100
committerTim Yates <tyates@picr.man.ac.uk>2013-09-02 13:02:53 +0100
commit95058aea96036fbdb4829d5245f5521541abdf0c (patch)
tree645055ff5b33f1efd8044bc96d8d7d73596b09db /groovy.html.markdown
parent6f444bece417a18127782d909a518c91962823c9 (diff)
Another way of checking List.contains and some headers
Diffstat (limited to 'groovy.html.markdown')
-rw-r--r--groovy.html.markdown15
1 files changed, 14 insertions, 1 deletions
diff --git a/groovy.html.markdown b/groovy.html.markdown
index 135efc0f..8fb1b346 100644
--- a/groovy.html.markdown
+++ b/groovy.html.markdown
@@ -74,20 +74,33 @@ technologies.remove("Griffon")
// Subtraction works also
technologies = technologies - 'Grails'
+/*** Iterating Lists ***/
+
// Iterate over elements of a list
technologies.each { println "Technology: $it"}
technologies.eachWithIndex { it, i -> println "$i: $it"}
+/*** Checking List contents ***/
+
//Evaluate if a list contains element(s) (boolean)
-technologies.contains('Groovy')
+contained = technologies.contains( 'Groovy' )
+
+// Or
+contained = 'Groovy' in technologies
+
+// Check for multiple contents
technologies.containsAll(['Groovy','Grails'])
+/*** Sorting Lists ***/
+
// Sort a list (mutates original list)
technologies.sort()
// To sort without mutating original, you can do:
sortedTechnologies = technologies.sort( false )
+/*** Manipulating Lists ***/
+
//Replace all elements in the list
Collections.replaceAll(technologies, 'Gradle', 'gradle')