Skip to content

[Code Issue] Typisiertes Stream-toArray #139

@tfeig

Description

@tfeig

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

Metadata

Metadata

Labels

bugSomething isn't workingslugNew or updated pattern snippet (category/slug.json)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions