From 6f444bece417a18127782d909a518c91962823c9 Mon Sep 17 00:00:00 2001 From: Tim Yates Date: Mon, 2 Sep 2013 12:59:18 +0100 Subject: Mention mutating with List.sort --- groovy.html.markdown | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'groovy.html.markdown') diff --git a/groovy.html.markdown b/groovy.html.markdown index 63cef76b..135efc0f 100644 --- a/groovy.html.markdown +++ b/groovy.html.markdown @@ -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') -- cgit v1.2.3