Replace concat String to append in StringBuilder parameters

Pavel Rappo pavel.rappo at
Tue Aug 19 15:00:12 UTC 2014


Yes, this works fine in cases when 'whatever' is a j.u.Collection<? extends CharSequence> (though some may argue that it's an overkill already). However we need even more thinking and transformations in case when 'whatever' is one of these:

   * j.u.Iterator<? extends CharSequence>
   * j.l.Iterable<? extends CharSequence>
   * j.u.Enumeration<? extends CharSequence>
   * CharSequence[]

In my opinion it's not that pretty:

   * Enumeration<String> whatever = ...;
     String s = Collections.list(whatever).stream().collect(joining(", "));

   * Iterable<String> whatever = ...;
     String s =, false /* or true */)
                             .collect(Collectors.joining(", "));

When we have one of these, it's even worse:

   * T[], where T is not an instance of CharSequence or T is primitive

     int[] whatever = ...;", "));

   * Iterable<Object> whatever = ...;
     String s =, false /* or true */)
                             .collect(Collectors.joining(", "));

I believe the most common case of joining objects into a string is either when objects are strings itself or they are made strings by calling Object::toString. For such a common and simple task there should be a convenient and concise one-liner.

I may be missing something.


On 19 Aug 2014, at 01:43, Brian Goetz <brian.goetz at> wrote:

> What you should have written was:
>  String s =", "));

More information about the core-libs-dev mailing list