Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.szaf.org!news.unit0.net!news.netfront.net!not-for-mail From: Wanja Gayk Newsgroups: comp.lang.java.programmer Subject: Re: for :each style question Date: Sat, 10 Dec 2011 13:28:56 +0100 Organization: Netfront http://www.netfront.net/ Lines: 39 Message-ID: References: <30fdd7tlkkejm29ufduhc9nnfk7uu3c6h0@4ax.com> NNTP-Posting-Host: 77.8.242.255 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: adenine.netfront.net 1323520133 99071 77.8.242.255 (10 Dec 2011 12:28:53 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Sat, 10 Dec 2011 12:28:53 +0000 (UTC) User-Agent: MicroPlanet-Gravity/3.0.4 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10645 In article , newsgroup.nospam@virtualinfinity.net says... > I find specific use-cases call for different approaches. For instance, > I like the following for string concatenation: > > final StringBuilder builder = new StringBuilder(); > > String sep = ""; > > for (Object o: objects) { > builder.append(sep).append(o); > sep = ", "; > } I always preferred to do it this way: final StringBuilder builder = new StringBuilder(); final String sep = ", "; for (final Object o: objects) { builder.append(o).append(sep); } builder.setLength(Math.max(0,builder.length()-sep.length())); The only drawback is that the size of the builder's internal buffer may grow unnecessarily, if the last separator crosses its current bounds, but how often does that happen and how often is it really a problem? Kind regards, Wanja -- ..Alesi's problem was that the back of the car was jumping up and down dangerously - and I can assure you from having been teammate to Jean Alesi and knowing what kind of cars that he can pull up with, when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer] --- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---