mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-22 12:32:09 +03:00
Mention mutating with List.sort
This commit is contained in:
parent
68f26804c5
commit
6f444bece4
@ -51,6 +51,7 @@ println x
|
||||
/*
|
||||
Collections and maps
|
||||
*/
|
||||
|
||||
//Creating an empty list
|
||||
def technologies = []
|
||||
|
||||
@ -81,9 +82,12 @@ technologies.eachWithIndex { it, i -> println "$i: $it"}
|
||||
technologies.contains('Groovy')
|
||||
technologies.containsAll(['Groovy','Grails'])
|
||||
|
||||
//Sort a list
|
||||
// Sort a list (mutates original list)
|
||||
technologies.sort()
|
||||
|
||||
// To sort without mutating original, you can do:
|
||||
sortedTechnologies = technologies.sort( false )
|
||||
|
||||
//Replace all elements in the list
|
||||
Collections.replaceAll(technologies, 'Gradle', 'gradle')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user