<div dir="ltr">Looking at the implementation, the code in toString suggest that it's worthwhile to optimize for an empty suffix (although I doubt that this optimization has any measurable effects). But the constructor always concatenates the prefix and the suffix, which results in both a new string instance and a StringBuilder. If an empty suffix is common (actually, having a separate constructor and the current toString implementation both suggest it is), I think that the initializing the emptyValue field in the constructor should be written as:<div>

<br></div><div><span style="color:rgb(0,0,0);font-size:12px">this.emptyValue = this.suffix.isEmpty() ? this.prefix : this.prefix + this.suffix;</span><br></div><div><br></div><div style><span style="color:rgb(0,0,0);font-size:12px">Actually, since there is also a setEmptyValue, I think that the field should be left null, and toString and length check for null, resulting in even less objects allocated in that scenario.</span></div>

<div style><span style="color:rgb(0,0,0);font-size:12px"><br></span></div><div style><span style="color:rgb(0,0,0);font-size:12px">Roel</span></div><div style><span style="color:rgb(0,0,0);font-size:12px"><br></span></div>

</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 3, 2013 at 5:43 PM,  <span dir="ltr"><<a href="mailto:paul.sandoz@oracle.com" target="_blank">paul.sandoz@oracle.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Changeset: a79e2683eae3<br>
Author:    psandoz<br>
Date:      2013-06-03 17:37 +0200<br>
URL:       <a href="http://hg.openjdk.java.net/jdk8/tl/jdk/rev/a79e2683eae3" target="_blank">http://hg.openjdk.java.net/jdk8/tl/jdk/rev/a79e2683eae3</a><br>
<br>
8014383: StringJoiner example in class description not in sync with streams API<br>
Reviewed-by: alanb<br>
<br>
! src/share/classes/java/util/StringJoiner.java<br>
<br>
</blockquote></div><br></div>