RFR: String.join(), StringJoiner additions

Martin Buchholz martinrb at google.com
Mon Apr 15 18:31:00 UTC 2013

It is natural to compare StringJoiner with guava Joiner.
Joiner is popular and has stood the test of time.

Joiner designers chose not to include a prefix and suffix, presumably
because that is an independent concern - it's not a "joining" activity.

OTOH, I'm guessing you are trying to improve the performance of operations
like List.toString.
More efficient (single copy char[]) would be to collect all the
sub-CharSequences in a CharSequence[],  pre-compute the final length of the
char[], allocate an array of exactly the required length, and create the
final string directly from that using the package-private constructor (but
in the unlikely event that a subsequence changed in size while concat'ing,
be prepared to resize the array).

On Thu, Apr 11, 2013 at 3:33 PM, Jim Gish <jim.gish at oracle.com> wrote:

> Please review http://cr.openjdk.java.net/~**jgish/Bugs-5015163-7175206-**
> 7172553/ <http://cr.openjdk.java.net/~jgish/Bugs-5015163-7175206-7172553/><
> http://cr.openjdk.java.net/%**7Ejgish/Bugs-5015163-7175206-**7172553/<http://cr.openjdk.java.net/%7Ejgish/Bugs-5015163-7175206-7172553/>
> >
> These are changes that we made in lambda that we're now bringing into JDK8.
> I've made a couple of additions - making StringJoiner final and adding a
> couple of constructors to set the emptyOutput chars.
> Thanks,
>    Jim
> --
> Jim Gish | Consulting Member of Technical Staff | +1.781.442.0304
> Oracle Java Platform Group | Core Libraries Team
> 35 Network Drive
> Burlington, MA 01803
> jim.gish at oracle.com

More information about the core-libs-dev mailing list