Skip to content

Provide Joiner as Collector #3951

Open
Open
@bjmi

Description

@bjmi

The main advantage of Guava Joiner over JDKs Collectors.joining(...) or StringJoiner that it can handle arbitrary objects and has a convenient builder api to express e.g. .useForNull(nullText).

Thus allow the usage of Joiner when streams come into play and get rid of cumbersome expressions like .filter(Objects::nonNull).map(Object::toString).

E.g. with factory method joiningOn(...):

objectStream.collect(joiningOn(", ").skipNulls());
objectStream.collect(joiningOn(", ").useForNull("<N/A>"));

Alternatively Joiner could implement Collector interface.

objectStream.collect(Joiner.on(", ").skipNulls());
objectStream.collect(Joiner.on(", ").useForNull("<N/A>"));

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions