X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: StringBuilder Difficulties Date: Tue, 28 Jun 2011 21:29:00 -0400 Organization: A noiseless patient Spider Lines: 52 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 29 Jun 2011 01:29:46 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="BrOwaJANne849xlH+KPYjQ"; logging-data="23052"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Oqaj50Iuh3r23BQ3AJNVy" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 In-Reply-To: Cancel-Lock: sha1:fXFIUNk5Ku0t7VDKOXLPeO4WE/E= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5758 On 6/28/2011 8:54 PM, Gene Wirchenko wrote: > Dear Java'ers: > > I am working with StringBuilder now. I grant that it is faster > in execution, but it is taking a bunch of my time to get it straight. > I decided to change my VRString class (call-by-value-result) to > VRStringB. Complications ensued. > > The amount of ornamentation required in my code was nasty, so I > did some simplifying. > > How does one assign a String value to a StringBuilder variable? One does not "assign" a reference of type T1 to a reference of unrelated type T2. One can, however, create a StringBuilder whose initial content is the same as that of a given String: String str = ...; // non-null StringBuilder sbd = new StringBuilder(str); These are "the same" in the sense that str.length() == sbc.length() and str.charAt(k) == sbd.charAt(k) for all 0 <= k < str.length(). Also, str.equals(sbd.toString()) returns true. > [...] > Am I missing something about StringBuilder, or is it really this > difficult to play with? You've been advised to read some Java tutorials or textbooks, and (it seems) have chosen not to follow that advice. Under the circumstances, then, I'd have to say StringBuilder is "really this difficult to play with." Perhaps you're "too pressed for time" to learn Java before writing it. Okay, yeah, that's reality, shit happens. But if so, you've been "pressed for time" for some weeks now, and (I'll wager) have already wasted more time chasing blind alleys than you would have spent learning the rudiments of the language. (A potential infinite regress looms.) > It would make a lot more sense to me if > StringBuilder worked more like String does. StringBuilder is only of interest because it is mutable, while String is immutable. From this fact flow many of the necessary differences that give you so much trouble, but that others take in stride. Summary: Fer Crissakes, Gene, read the damn' book! -- Eric Sosman esosman@ieee-dot-org.invalid