Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 6
    More precisely: StringBuffer for jdk1.4 and below, StringBuilder for jdk1.5 and after, since the latter is not synchronized, hence a little faster. Commented Oct 9, 2008 at 15:39
  • 2
    Istead of two iter.hasNext() invocations I usually append delimeter and then "return buf.substring(0, buf.length() - delimeter.length())". Commented Oct 9, 2008 at 15:40
  • 2
    You can streamline it a tiny bit by exiting early to avoid the delimiter: while (true) ( add_iter; if (! iter.hasNext()) break; add_delim; } Commented Mar 21, 2009 at 12:50