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