Skip to content

Commit 5716f4f

Browse files
Copilotbrunoborges
andauthored
fix: add missing filter(length > 3) to oldCode in stream-toarray-typed
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com> Agent-Logs-Url: https://github.com/javaevolved/javaevolved.github.io/sessions/400db364-bc8d-4e00-bf81-2b98945e411b
1 parent 2d760ff commit 5716f4f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

content/collections/stream-toarray-typed.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ oldApproach: "Manual Array Copy"
1111
modernApproach: "toArray(generator)"
1212
oldCode: |-
1313
List<String> list = getNames();
14-
String[] arr = new String[list.size()];
15-
for (int i = 0; i < list.size(); i++) {
16-
arr[i] = list.get(i);
14+
List<String> filtered = new ArrayList<>();
15+
for (String n : list) {
16+
if (n.length() > 3) {
17+
filtered.add(n);
18+
}
1719
}
20+
String[] arr = filtered.toArray(new String[0]);
1821
modernCode: |-
1922
String[] arr = getNames().stream()
2023
.filter(n -> n.length() > 3)

0 commit comments

Comments
 (0)