Skip to content

Comments

Highlight Stream.toList() as the modern approach in Unmodifiable collectors#80

Merged
brunoborges merged 3 commits intomainfrom
copilot/update-unmodifiable-collectors
Feb 24, 2026
Merged

Highlight Stream.toList() as the modern approach in Unmodifiable collectors#80
brunoborges merged 3 commits intomainfrom
copilot/update-unmodifiable-collectors

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

stream.toList() (Java 16+) is the simplest way to collect a stream into an unmodifiable list — no collect() call or Collectors import needed. The "Unmodifiable collectors" pattern now highlights this as the primary modern approach.

Changes

  • unmodifiable-collectors.json: Promoted stream.toList() to the modern approach (modernCode, modernLabel → "Java 16+", modernApproach, summary, whyModernWins, support). The explanation still covers Java 10's toUnmodifiableList()/toUnmodifiableSet()/toUnmodifiableMap() as context for other collection types. Added both Stream.toList() and Collectors.toUnmodifiableList() Javadoc links in docs. Replaced collections/map-entry-factory in related with streams/stream-tolist.
  • stream-tolist.json: Added collections/unmodifiable-collectors to related for bidirectional linking (replacing streams/virtual-thread-executor).
  • Regenerated all HTML from updated JSON sources.
// Before (Java 8) — old approach
List<String> list = stream.collect(
    Collectors.collectingAndThen(
        Collectors.toList(),
        Collections::unmodifiableList
    )
);

// After (Java 16+) — modern approach
List<String> list = stream.toList();
Original prompt

This section details on the original issue you should resolve

<issue_title>#collections in "Unmodifiable collectors" suggest using or mention of Stream.toList()</issue_title>
<issue_description>The java.util.Stream.toList() specifies an immutable List as the return type. So the stream.collect(Collectors.toUnmodifiableList()) may be simplified to stream.toList()</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Suggest using Stream.toList() for unmodifiable collectors Suggest Stream.toList() as simpler alternative in Unmodifiable collectors Feb 23, 2026
@brunoborges brunoborges marked this pull request as ready for review February 23, 2026 22:44
@brunoborges
Copy link
Contributor

@copilot well, why don't we stick to highlighting the JDK 16+ approach then?

Copy link
Contributor Author

Copilot AI commented Feb 24, 2026

@copilot well, why don't we stick to highlighting the JDK 16+ approach then?

Done in 73bec43. The pattern now features stream.toList() (Java 16+) as the modern approach directly — the modernCode is List<String> list = stream.toList();, version label is "Java 16+", and the explanation still covers toUnmodifiableList()/toUnmodifiableSet()/toUnmodifiableMap() as context for other collection types. Both Stream.toList() and Collectors.toUnmodifiableList() Javadoc links are included in docs.

Copilot AI changed the title Suggest Stream.toList() as simpler alternative in Unmodifiable collectors Highlight Stream.toList() as the modern approach in Unmodifiable collectors Feb 24, 2026
@brunoborges brunoborges merged commit 3ed8a04 into main Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#collections in "Unmodifiable collectors" suggest using or mention of Stream.toList()

2 participants