Replace concat String to append in StringBuilder parameters

Pavel Rappo pavel.rappo at
Mon Aug 11 16:17:53 UTC 2014


My point was simply that none of these classes provide methods that accept java.lang.Object. IMO, the scenario when we join elements into a String by calling toString on each element prior to append it -- is the most common scenario (maybe except for when element is a String itself). That is instead of doing this:

	Iterable<?> whatever = ...
	String s = String.join(whatever);

we have to do (at least) something like this:

	Iterable<?> whatever = ...
	whatever.forEach(w -> builder.append(w.toString());
	String s = builder.toString();

or this:

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

That is, it's hardly ever a concise one-liner. An 'addAll' method in j.u.StringJoiner could have saved us, but there isn't one.

(I'm sure there were plenty of engineering reasons not to do things I've mentioned)


On 11 Aug 2014, at 16:38, Ulf Zibis <Ulf.Zibis at> wrote:

> Am 11.08.2014 um 16:33 schrieb Pavel Rappo:
>> Unfortunately, neither java.util.StringJoiner nor String.join have perfect (but who has?) APIs. So it's up to us to figure out the best way of joining elements.
> Maybe remember my thoughts from here:
> Would it be possible to inherit StringJoiner from StringBuilder in some way?
> Then a mixture of concatanation, StringBuilder and StringJoiner after Javac would end up in one StringBuilder instance. We also could profit from StringJoiners initial capacity capability.
> -Ulf

More information about the core-libs-dev mailing list