mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Added a few more examples for List manipulation
This commit is contained in:
parent
39b96dd2db
commit
68f26804c5
@ -54,14 +54,25 @@ 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")
|
||||
|
||||
// Subtraction works also
|
||||
technologies = technologies - 'Grails'
|
||||
|
||||
// Iterate over elements of a list
|
||||
technologies.each { println "Technology: $it"}
|
||||
technologies.eachWithIndex { it, i -> println "$i: $it"}
|
||||
|
Loading…
Reference in New Issue
Block a user