diff options
author | Levi Bostian <levi.bostian@banno.com> | 2013-11-25 09:42:37 -0600 |
---|---|---|
committer | Levi Bostian <levi.bostian@banno.com> | 2013-11-25 09:42:37 -0600 |
commit | af6701904b459b16cf65709cd8c70fd2f5519457 (patch) | |
tree | 68cb4bf9ead32686f492e68528e9f0761e41c500 /groovy.html.markdown | |
parent | df3cc00f5233dac96c0e063d87d3552f493e25f6 (diff) | |
parent | d24c824d388669181eed99c3e94bb25c2914304a (diff) |
Fix conflict bash.
Diffstat (limited to 'groovy.html.markdown')
-rw-r--r-- | groovy.html.markdown | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/groovy.html.markdown b/groovy.html.markdown index 1a635e59..8fb1b346 100644 --- a/groovy.html.markdown +++ b/groovy.html.markdown @@ -8,7 +8,7 @@ filename: learngroovy.groovy Groovy - A dynamic language for the Java platform [Read more here.](http://groovy.codehaus.org) -```cpp +```groovy /* Set yourself up: @@ -51,28 +51,56 @@ println x /* Collections and maps */ + //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' + +/*** 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']) -//Sort a list +/*** 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') |