RFR: String.join(), StringJoiner additions (original) (raw)

Jim Gish jim.gish at oracle.com
Thu Apr 18 17:34:54 UTC 2013


That was a nice idea, but you don't want to change the value when you do toString(). Otherwise, if you subsequently add a new element, you're hosed because you've already added on the suffix.

Jim

On 04/17/2013 09:20 PM, Roger Riggs wrote: > Hi, >> Can I suggest that the StringJoiner.toString() method explicitly > append the suffix > to the existing StringBuilder. >> 152 return (value != null ? value.toString() + suffix : > emptyValue); >> Currently it will go to the trouble of creating a String from the > builder and then > transparently create another StringBuilder to do the concatenation. >> 152 return (value != null ? value.append(suffix).toString() : > emptyValue); >> or something similar. >> The overhead of StringJoiner supporting prefix and suffix is lower > than doing it separately > in terms of object allocations and garbage and all places that would > need write their > own code to do the concatenation. >> Roger >>> On 4/17/13 5:49 PM, Jim Gish wrote: >> Here's an update: >> http://cr.openjdk.java.net/~jgish/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 . 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:: >>>>>> -
isn't needed around
 as it's already a 
you
>>> probably mean to do >>>>>>
 {@code
>>> ... >>> } >>>>>> 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/> >>>>>>>> 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 >>>>>>>

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