Skip to content

Commit

Permalink
Another way of checking List.contains and some headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Yates committed Sep 2, 2013
1 parent 6f444be commit 95058ae
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion groovy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 95058ae

Please sign in to comment.