----- Original Message -----
> From: "Tagir Valeev" <[email protected]>
> To: "core-libs-dev" <[email protected]>, "Naoto Sato"
> <[email protected]>
> Sent: Thursday, September 3, 2026 9:37:05 AM
> Subject: [SPAM] [External] : Collector for ListFormat
> Hello!
>
> I recently discovered the java.text.ListFormat API which appeared since
> Java 22. It's great and useful, but I feel that it misses a Collector. It's
> very possible that the original strings are available in the Stream, rather
> than in the List, and it would be nice to be able to join the stream
> directly, without intermediate List, like we can do with
> Collectors.joining(). So I would propose adding a new instance method to
> ListFormat, like
>
> public Collector<String, ?, String> formatting() {...}
>
> or probably, to be more consistent with Collectors.joining(), it could be
>
> public Collector<CharSequence, ?, String> formatting() {...}
>
> The initial implementation could be trivial:
>
> public Collector<CharSequence, ?, String> formatting() {
> return
> Collectors.collectingAndThen(Collectors.mapping(CharSequence::toString,
> Collectors.toList()), this::format);
> }
>
> Or without 'mapping' step, if we want to limit the input to strings.
>
> What do you think?
Hello,
Being an instance method of ListFormat is a nice idea, i'm sure you can come
with a better implementation because you have access to the private state of
ListFormat.
I would prefer a name like "toCollector()" more than "formatting", given it's
an instance method of ListFormat
stream.collect(listFormat.toCollector())
vs
stream.collect(listFormat.formatting())
regards,
Rémi
>
> With best regards,
> Tagir Valeev