Skip to content

Fix stream-toarray-typed: old code missing filter(length > 3)#144

Merged
brunoborges merged 2 commits intomainfrom
copilot/fix-stream-toarray-typed-issue
Mar 25, 2026
Merged

Fix stream-toarray-typed: old code missing filter(length > 3)#144
brunoborges merged 2 commits intomainfrom
copilot/fix-stream-toarray-typed-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

The oldCode example for stream-toarray-typed was not functionally equivalent to modernCode — it copied all elements unconditionally while the modern version filters by n.length() > 3.

Change

Updated oldCode to use the pre-Streams idiomatic equivalent with an explicit filter loop:

// Before — missing the filter entirely
List<String> list = getNames();
String[] arr = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
    arr[i] = list.get(i);
}

// After — functionally equivalent to the modern stream pipeline
List<String> list = getNames();
List<String> filtered = new ArrayList<>();
for (String n : list) {
    if (n.length() > 3) {
        filtered.add(n);
    }
}
String[] arr = filtered.toArray(new String[0]);

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix compilation issue with stream toArray type Fix stream-toarray-typed: old code missing filter(length > 3) Mar 25, 2026
Copilot AI requested a review from brunoborges March 25, 2026 14:17
@brunoborges brunoborges marked this pull request as ready for review March 25, 2026 15:13
@brunoborges brunoborges merged commit d735465 into main Mar 25, 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.

[Code Issue] toArray typé dans les streams

2 participants