Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news-peer.in.tum.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nigel Wade Newsgroups: comp.lang.java.help Subject: Re: Change decimal color code on the fly Date: Fri, 16 Nov 2012 16:52:25 +0000 Lines: 42 Message-ID: References: <5509b9ea-041a-46e6-b788-2abe90fcb8e7@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net buxOS3NytzeeyUf/wLxV7w8hmdIVa2utHW6p/bjxyCGfnEdfNbcUDLxbtDkxpe+EAi Cancel-Lock: sha1:Jy8zAAKjNrYrIhDVHZxr5+kUiMQ= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 In-Reply-To: <5509b9ea-041a-46e6-b788-2abe90fcb8e7@googlegroups.com> Xref: csiph.com comp.lang.java.help:2273 On 16/11/12 16:05, Bob wrote: > Hi All, > While making a datafile of decimal color pixel > codes for a small image, I want to change > a particular String number that will go into the datafile > to a different String number. > I am doing this before it is added to the > ArrayList. It does not seem to work and I need > to know why. Below is my test to identify > the String number and looking for the "if" > statement to recognize it" > > Here is a snip of my code: > .... > mSet = redStr + greenStr + blueStr; > System.out.println(mSet);//this is successful > mSetx= "255255255"; > > if (mSet == mSetx) { > System.out.println("yes, recognized"); > //mSet = ("113000000"); > } > colorpxl.add(mSet);// ArrayList > mSet = ""; > > Thanks in advance for your response. > > Bob You are using the wrong test. == tests for equality of the reference, not equality of what is referenced. It has no knowledge of String and cannot compare the actual contents of a String. All it does is compare the references mSet and mSetx. These refer to two different Strings, even though the Strings may contain the same sequence of characters, and therefore the test fails. What you need is String.equals(). -- Nigel Wade