Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: I need a different approach - suggestions please Date: Thu, 28 Jun 2012 07:32:17 -0700 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 28 Jun 2012 14:32:19 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="Aj4gkJnboYPtscrbpd0V8g"; logging-data="8226"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nGE/UMwWJQlDK0Cu9YztwV4fw9i4vo9M=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: Cancel-Lock: sha1:2crgBzPgKMRNw5LsxWU3VWW4/D4= Xref: csiph.com comp.lang.java.programmer:15719 On 6/28/2012 4:02 AM, bilsch wrote: > if( btn.equals( "1" ) || btn.equals( "2" ) || btn.equals( "3" ) > || btn.equals( "4" ) > || btn.equals( "5" ) || btn.equals( "6" ) || btn.equals( > "7" ) || btn.equals( "8" ) > || btn.equals( "9" ) || btn.equals( "0" ) || btn.equals( > "." )) { Wow, you actually changed it. Good job. I have to say that I like ".0123456789".contains( btn ) better. It's much shorter. ;-) > if (btn == "+") { You really do need to change all of the other string comparisons to .equals() too. This == stuff is going to fail unpredictably for you. It tests for object identity (i.e., to objects are the same object) and is only going to succeed for strings by luck at this point. .equals() checks that the contents of the string are the same. I'll stop there because any other errors might be masked by these == comparisons for strings.