This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git
The following commit(s) were added to refs/heads/asf-site by this push:
new 786dd07 add subList
786dd07 is described below
commit 786dd07160e02049d86db34580cc0f12a7214c64
Author: Paul King <[email protected]>
AuthorDate: Tue May 27 11:20:20 2025 +1000
add subList
---
site/src/site/releasenotes/groovy-5.0.adoc | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/site/src/site/releasenotes/groovy-5.0.adoc
b/site/src/site/releasenotes/groovy-5.0.adoc
index 983427c..88d9819 100644
--- a/site/src/site/releasenotes/groovy-5.0.adoc
+++ b/site/src/site/releasenotes/groovy-5.0.adoc
@@ -432,6 +432,18 @@ nums.indices.every {
}
----
+The JDK's `List#subList` method is very handy for working with mutating
methods from the JDK Collections API
+on part of a list. Groovy 5, now offers a version of that method taking a
range.
+
+[source,groovy]
+----
+def fruit = ['🍏', '🍎', '🍉', '🍋', '🍇']
+def apples = fruit.subList(0..<2)
+assert apples == ['🍏', '🍎']
+apples.clear()
+assert fruit == ['🍉', '🍋', '🍇']
+----
+
A known feature of some queues within the JDK Collections API,
is that the standard iterator for queues like `PriorityQueue` don't return
elements in priority order.
Instead, the `poll()` method is used to return the next highest priority
element.