On 04/09/2026 10:07, Tagir Valeev wrote:
Hi, Viktor!
On Thu, Sep 3, 2026 at 5:19 PM Viktor Klang <[email protected]> wrote:
Just chiming in,
I suspect that more developers know/use Collectors.<x>() than
ListFormat, so for discoverability purposes I suspect that a
Collectors.listFormatting(…) would be better.
I see the reason, but I would rather keep it in ListFormat. I feel
that even though both java.text and java.util (including
java.util.stream)
belong to java.base, the java.text API is more high-level, and
java.util is more basic/fundamental. So I'd avoid code references from
java.util to java.text.
We indeed have some references from java.util to java.text (in
Scanner, Pattern, Formatter, Calendar, Date, and Locale classes),
but I'm reluctant to add more.
Another thing is that instance methods are easier to use and easier to read.
I like Remi's suggestion to add a cross-link from Collectors.joining
to ListFormat.toCollector. A javadoc link is a weaker dependency,
which looks acceptable here.
Well, probably other maintainers have another opinion. If we post CSR,
more people will participate in the discussion.
A Collectors.formatting that sits along side Collectors.joining might
not be too terrible. They both concatenates elements in encounter order.
We could think of the new method as being "joining on steroids" in that
it would do the locale specific punctuation and concatenating.
So I think it is worth trying this:
Collector<String, ?, String> formatting(ListFormat format)
which would give you usages like:
ListFormat format = ListFormat.getInstance(Locale.US,
ListFormat.Type.OR, ListFormat.Style.FULL);
String result = Stream.of("foo", "bar", "baz")
.collect(Collectors.formatting(format));
> foo, bar, or baz
It would be more discoverable and avoids avoid having to keep a
reference to a Collector like you would have if it were a method on
ListFormat, e.g.
Collector<CharSequence, ?, String> collector =
ListFormat.getInstance(
Locale.US,
ListFormat.Type.OR,
ListFormat.Style.FULL
).toCollector();
String result = Stream.of("foo", "bar", "baz")
.collect(collector);
-Alan