RFR: String.join(), StringJoiner additions

Brian Goetz brian.goetz at oracle.com
Thu Apr 18 01:10:01 UTC 2013


The motivation was indeed that it would support more efficient 
Collection.toString.  (But, I don't believe anything actually uses that 
feature right now, other than tests.)

Even if *our* implementations were not to use this because we had a 
better for-experts construction, I still think this is a useful feature 
that users classes may benefit from in their own toString methods.

On 4/17/2013 6:15 PM, Jim Gish wrote:
> I'm open to this, but am interested in what others have to say,
> especially as it relates to other lambda features coming in.  Bear in
> mind that this is at least the third major round of reviews for these
> changes, the first round being a year ago on lambda-dev, when I first
> submitted them, and then they were distilled some more and greatly
> simplified by Henry Jen.
>
> Thanks,
>     Jim
>
> On 04/17/2013 06:07 PM, Martin Buchholz wrote:
>> I'm still wondering about whether a joiner utility should support a
>> prefix and suffix.  The obvious uses for this are collection class
>> toString methods, but we already know that we can and should implement
>> those with a single precise char[] construction, so should not use
>> StringJoiner, or at least not this StringJoiner implementation.  And
>> if we're just talking about pure convenience, it's hard to beat
>>
>> "[" + String.join(...) + "]"
>>
>>
>> On Wed, Apr 17, 2013 at 2:49 PM, Jim Gish <jim.gish at oracle.com
>> <mailto:jim.gish at oracle.com>> wrote:
>>
>>     Here's an update:
>>     http://cr.openjdk.java.net/~jgish/Bugs-5015163-7172553/
>>     <http://cr.openjdk.java.net/%7Ejgish/Bugs-5015163-7172553/>
>>     <http://cr.openjdk.java.net/%7Ejgish/Bugs-5015163-7172553/>
>>
>>     Jim
>>
>>
>>     On 04/17/2013 03:15 PM, Mike Duigou wrote:
>>
>>         String::
>>
>>         line 1253: This should use {@code } rather than <code></code>.
>>         I think regular spaces are OK as well.   seems
>> inappropriate.
>>
>>         lines 2425/2467: elements may not be null either.
>>
>>         I can tell you (or maybe it's just me) are itching to change :
>>
>>         for (CharSequence cs: elements) {
>>         2477             joiner.add(cs);
>>         2478         }
>>
>>         to:
>>
>>         elements.forEach(joiner::add);
>>
>>         StringJoiner::
>>
>>         - <blockquote> isn't needed around <pre> as it's already a
>>         <div> you probably mean to do
>>
>>         <pre> {@code
>>         ...
>>         }</pre>
>>
>>         for code samples.
>>
>>         - It would be nice if the empty output generation in three arg
>>         constructor could be suppressed unless needed. Perhaps a
>>         special (not null please!) sentinel value?
>>
>>         - Four arg constructor doesn't include emptyOutput in @throws NPE
>>
>>
>>         On Apr 11 2013, at 15:33 , Jim Gish wrote:
>>
>>             Please review
>>
>> 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 <tel:%2B1.781.442.0304>
>>             Oracle Java Platform Group | Core Libraries Team
>>             35 Network Drive
>>             Burlington, MA 01803
>>             jim.gish at oracle.com <mailto:jim.gish at oracle.com>
>>
>>
>>     --     Jim Gish | Consulting Member of Technical Staff |
>> +1.781.442.0304
>>     <tel:%2B1.781.442.0304>
>>     Oracle Java Platform Group | Core Libraries Team
>>     35 Network Drive
>>     Burlington, MA 01803
>>     jim.gish at oracle.com <mailto:jim.gish at oracle.com>
>>
>>
>



More information about the core-libs-dev mailing list