From ebe887fc6890a5203ff4fc897ad3667d94ba641f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 20:07:15 +0000 Subject: [PATCH 1/3] Initial plan From 89ed6e0c6ca3beb8c540fb2993cfe607c93aa711 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 20:10:24 +0000 Subject: [PATCH 2/3] Suggest Stream.toList() in Unmodifiable collectors pattern Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com> --- content/collections/unmodifiable-collectors.json | 4 ++-- content/streams/stream-tolist.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/collections/unmodifiable-collectors.json b/content/collections/unmodifiable-collectors.json index 0a9b1f5..08fcd24 100644 --- a/content/collections/unmodifiable-collectors.json +++ b/content/collections/unmodifiable-collectors.json @@ -12,7 +12,7 @@ "oldCode": "List list = stream.collect(\n Collectors.collectingAndThen(\n Collectors.toList(),\n Collections::unmodifiableList\n )\n);", "modernCode": "List list = stream.collect(\n Collectors.toUnmodifiableList()\n);", "summary": "Collect directly to unmodifiable collections.", - "explanation": "Java 10 added toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() collectors. No more wrapping with collectingAndThen.", + "explanation": "Java 10 added toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() collectors. No more wrapping with collectingAndThen. For lists specifically, Java 16+ stream.toList() is even simpler — it returns an unmodifiable List without the collect() call.", "whyModernWins": [ { "icon": "📏", @@ -39,7 +39,7 @@ "related": [ "collections/immutable-map-creation", "collections/immutable-set-creation", - "collections/map-entry-factory" + "streams/stream-tolist" ], "docs": [ { diff --git a/content/streams/stream-tolist.json b/content/streams/stream-tolist.json index 43b510c..4c6dbcc 100644 --- a/content/streams/stream-tolist.json +++ b/content/streams/stream-tolist.json @@ -37,7 +37,7 @@ "prev": "streams/collectors-flatmapping", "next": "streams/stream-mapmulti", "related": [ - "streams/virtual-thread-executor", + "collections/unmodifiable-collectors", "streams/stream-gatherers", "streams/stream-iterate-predicate" ], From 73bec43c39f9dba05a8664fc22f37b21a1b3eb4c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Feb 2026 16:20:42 +0000 Subject: [PATCH 3/3] Highlight stream.toList() as the modern approach in Unmodifiable collectors Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com> --- .../collections/unmodifiable-collectors.json | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/content/collections/unmodifiable-collectors.json b/content/collections/unmodifiable-collectors.json index 08fcd24..57f8705 100644 --- a/content/collections/unmodifiable-collectors.json +++ b/content/collections/unmodifiable-collectors.json @@ -4,20 +4,20 @@ "title": "Unmodifiable collectors", "category": "collections", "difficulty": "intermediate", - "jdkVersion": "10", + "jdkVersion": "16", "oldLabel": "Java 8", - "modernLabel": "Java 10+", + "modernLabel": "Java 16+", "oldApproach": "collectingAndThen", - "modernApproach": "toUnmodifiable*()", + "modernApproach": "stream.toList()", "oldCode": "List list = stream.collect(\n Collectors.collectingAndThen(\n Collectors.toList(),\n Collections::unmodifiableList\n )\n);", - "modernCode": "List list = stream.collect(\n Collectors.toUnmodifiableList()\n);", - "summary": "Collect directly to unmodifiable collections.", - "explanation": "Java 10 added toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() collectors. No more wrapping with collectingAndThen. For lists specifically, Java 16+ stream.toList() is even simpler — it returns an unmodifiable List without the collect() call.", + "modernCode": "List list = stream.toList();", + "summary": "Collect directly to an unmodifiable list with stream.toList().", + "explanation": "Java 10 added toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() to replace the verbose collectingAndThen wrapper. For lists specifically, Java 16's stream.toList() provides an even simpler alternative — no collect() call at all. Use toUnmodifiableSet() and toUnmodifiableMap() for other collection types.", "whyModernWins": [ { "icon": "📏", - "title": "Direct", - "desc": "One collector instead of wrapping with collectingAndThen." + "title": "Shortest yet", + "desc": "stream.toList() needs no collect() or Collectors import at all." }, { "icon": "🔒", @@ -25,14 +25,14 @@ "desc": "Result cannot be modified — no accidental mutations." }, { - "icon": "🚫", - "title": "Null-safe", - "desc": "Rejects null elements during collection." + "icon": "📖", + "title": "Readable", + "desc": "Reads naturally as the terminal step of any stream pipeline." } ], "support": { "state": "available", - "description": "Widely available since JDK 10 (March 2018)" + "description": "Widely available since JDK 16 (March 2021)" }, "prev": "collections/reverse-list-iteration", "next": "strings/string-isblank", @@ -42,6 +42,10 @@ "streams/stream-tolist" ], "docs": [ + { + "title": "Stream.toList()", + "href": "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/stream/Stream.html#toList()" + }, { "title": "Collectors.toUnmodifiableList()", "href": "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/stream/Collectors.html#toUnmodifiableList()"