Mention mutating with List.sort

This commit is contained in:
Tim Yates 2013-09-02 12:59:18 +01:00
parent 68f26804c5
commit 6f444bece4

View File

@ -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')