Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: StringBuilder Difficulties Date: Wed, 29 Jun 2011 22:06:18 -0400 Organization: A noiseless patient Spider Lines: 82 Message-ID: References: <5otm07t5lrvp0me457o7f3s2lpe7uo5mk6@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 30 Jun 2011 02:07:10 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="BrOwaJANne849xlH+KPYjQ"; logging-data="8831"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/tNepXO2trrHBFivP/eCw" 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: <5otm07t5lrvp0me457o7f3s2lpe7uo5mk6@4ax.com> Cancel-Lock: sha1:F08wA9MxuZMsdSuVQSSdqi2RvlQ= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5792 On 6/29/2011 3:11 PM, Gene Wirchenko wrote: > On Tue, 28 Jun 2011 21:29:00 -0400, Eric Sosman > wrote: > >> 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 > ^^^^^^^^^ > I wrote "value". You also wrote "assign." The only values Java can "assign" are primitives and references -- in particular, Java cannot "assign" the sequence of characters that make up the content of a String or a StringBuilder. >> String str = ...; // non-null >> StringBuilder sbd = new StringBuilder(str); > > I have found that, but I was wondering about how to do it with > the same StringBuilder object. I thought that part of the advantage > of using StringBuilder was that the amount of object creation got cut > down. Not sure what the "it" you mention is. The efficiency "advantage," to the extent that there is one, is illustrated by String result = ""; for (String s : bigBunchOfStrings) result += s; vs. StringBuilder buff = new StringBuilder(); for (String s : bigBunchOfStrings) buff.append(s); String result = buff.toString(); >> 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. > > IOW, a String value assigned to a StringBuilder variable. See above; this is not "assignment." >> 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." > > Which I have. I have been referring to the docs for > StringBuilder, but the docs are rather incomplete, and I have to > guess. This takestime. Elsethread you mention that you've programmed in "quite a few programming languages." Did you study them as diligently as you're studying Java, or are you like the Real Programmer who "can write FORTRAN in any language?" Okay, if you've got a distaste for Java and are reluctant to learn it, that's the way it goes. I've resisted C++ for years and years on equally flimsy grounds. But if you're just trying to "get by" and don't intend to learn, then at the very least stop whining! > I know the rudiments. I am having trouble with the next level. IMHO you do not yet know the rudiments. -- Eric Sosman esosman@ieee-dot-org.invalid