We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents f0470ed + 5716f4f commit d735465Copy full SHA for d735465
content/collections/stream-toarray-typed.yaml
@@ -11,10 +11,13 @@ oldApproach: "Manual Array Copy"
11
modernApproach: "toArray(generator)"
12
oldCode: |-
13
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);
+ List<String> filtered = new ArrayList<>();
+ for (String n : list) {
+ if (n.length() > 3) {
17
+ filtered.add(n);
18
+ }
19
}
20
+ String[] arr = filtered.toArray(new String[0]);
21
modernCode: |-
22
String[] arr = getNames().stream()
23
.filter(n -> n.length() > 3)
0 commit comments