Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2271
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Change decimal color code on the fly |
| Date | 2012-11-16 11:49 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <k85qq1$18c$1@dont-email.me> (permalink) |
| References | <5509b9ea-041a-46e6-b788-2abe90fcb8e7@googlegroups.com> |
On 11/16/2012 11:05 AM, 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"
I'm not sure what your problem is, so my comments
may be off the mark ...
> Here is a snip of my code:
> ....
> mSet = redStr + greenStr + blueStr;
> System.out.println(mSet);//this is successful
> mSetx= "255255255";
>
> if (mSet == mSetx) {
It looks like `mSet' and `mSetx' are String references.
If so, the `==' operator is probably the wrong thing to use;
most likely `mSet.equals(mSetx)' or `mSetx.equals(mSet)' is
what you intend.
`==' asks "Do these two references denote the exact same
String instance?"
equals() asks "Do these Strings have the same value?"
Analogy: Imagine you've found a dollar bill on the street,
and that you later fed it into a vending machine in exchange
for a candy bar. Imagine also that you have another dollar
bill in your wallet. You can now refer to "the dollar I found"
and to "the dollar I spent" and to "the dollar in my wallet."
A hypothetical equals() method for dollar bills would declare
that all three of these notions refer to a dollar bill with the
same value as the others (and as themselves), but the `=='
operator would say the first two differ from the third (the
"found" bill and the "spent" bill refer to the same physical
scrap of green paper, while the "wallet" bill refers to a
different one). If your problem is that the `if' doesn't seem
to work, this is probably why.
> System.out.println("yes, recognized");
> //mSet = ("113000000");
> }
> colorpxl.add(mSet);// ArrayList
> mSet = "";
Or perhaps this is what confuses you. `mSet' is not a
String object, but a reference to a String object. Somewhere
"out there" is a String that `mSet' once referred to; the
ArrayList also has a reference to that same String. When you
change `mSet' to refer to a different String (an empty String),
you do not change the ArrayList's reference to the original.
If you expected the final assignment to change what's in the
ArrayList -- well, it won't.
--
Eric Sosman
esosman@comcast-dot-net.invalid
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Change decimal color code on the fly Bob <bherbst65@hotmail.com> - 2012-11-16 08:05 -0800
Re: Change decimal color code on the fly Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-16 11:49 -0500
Re: Change decimal color code on the fly markspace <-@.> - 2012-11-16 08:50 -0800
Re: Change decimal color code on the fly Nigel Wade <nmw@ion.le.ac.uk> - 2012-11-16 16:52 +0000
Re: Change decimal color code on the fly Roedy Green <see_website@mindprod.com.invalid> - 2012-11-16 10:14 -0800
Re: Change decimal color code on the fly Bob <bherbst65@hotmail.com> - 2012-11-16 10:39 -0800
Re: Change decimal color code on the fly Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-16 13:56 -0500
Re: Change decimal color code on the fly Bob <bherbst65@hotmail.com> - 2012-11-16 12:23 -0800
Re: Change decimal color code on the fly Lew <lewbloch@gmail.com> - 2012-11-16 12:38 -0800
Re: Change decimal color code on the fly Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-16 17:11 -0500
csiph-web