Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 29 Jun 2011 16:38:13 -0500 Date: Wed, 29 Jun 2011 14:38:04 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: StringBuilder Difficulties References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 28 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.196.78 X-Trace: sv3-jxD7aesOqYNaveyIvA/3mwTeVPpbqKhswm5/MHarPjHTQx9q12BnRNAKNS9kdY4Zzjyrv12EzljvnXL!+825s4g5A+gMelUIOQ927GmQ4oHKcdtx//hs6xgD3wI85OIEoZEUjbyw9Co+ctpDgHy6cV9D/717!HKo36QF6u7pk1tz2OnZZo1Ogn3qtflws3BCwfC0X1X1lHQ== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2077 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5784 On 6/28/2011 5:54 PM, Gene Wirchenko wrote: ... > Am I missing something about StringBuilder, or is it really this > difficult to play with? It would make a lot more sense to me if > StringBuilder worked more like String does. ... The main thing you seem to be missing about StringBuilder is that it is not a string, it is a tool for building strings. Here is some sample code demonstrating comparing a String to the current contents of a StringBuilder, and replacing the entire contents with a different String. public class StringBuilderExample { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); sb.append("aaa"); System.out.println(sb); System.out.println("aaa".equals(sb.toString())); sb.replace(0, Integer.MAX_VALUE, "bbbbbbb"); System.out.println(sb); } } Patricia