Category
collections
Pattern slug
stream-toarray-typed
Which code is affected?
Both
Type of issue
Other
Describe the issue
The old code only shows how a list is converted to an array, without the filtering which happens in the stream variant.
This could quite simply be done with String[] arr = list.toArray(new String[0]);
So either we also filter in the old version - which would then indeed require a for loop. Or the we don't filter in the new version, in which case I'd argue that getNames().toArray(new String[0]); is actually simpler/better than getNames().stream().toArray(String[]::new);.
Suggested fix
JDK version tested
No response
Category
collections
Pattern slug
stream-toarray-typed
Which code is affected?
Both
Type of issue
Other
Describe the issue
The old code only shows how a list is converted to an array, without the filtering which happens in the stream variant.
This could quite simply be done with
String[] arr = list.toArray(new String[0]);So either we also filter in the old version - which would then indeed require a for loop. Or the we don't filter in the new version, in which case I'd argue that
getNames().toArray(new String[0]);is actually simpler/better thangetNames().stream().toArray(String[]::new);.Suggested fix
JDK version tested
No response