Subhash
Subhash
Subhash
You said it! It nails every Java beginner as they're learning, and it continues to trip up Java experts to no end. One more trick to be aware of is that Object's definition of equals() is equivalent to ==.Originally posted by Subhash L. Sriram:
Man, that .equals(theItem) and == sure are tricky, huh?
Subhash
Subhash
Subhash
Oops, you found it while I was writing my post. Also, no mistake is stupid if you learn from it.Originally posted by Subhash L. Sriram:
Like I said, it was a stupid mistake that I figured out, but thank you for the explanation, it is easier to understand it now.
Originally posted by M Beck:
oh, and about the possible suggestion i had -- since, even though it turned out not to be necessary in this case, it might come in handy elsewhere:
basically, you want to look at the last character of the string, check to see if it's a character you might be interested in (like a letter, maybe), and go on looking towards the start of the string if it's not. when you find the first character of the string (counting from the end) that's one of the characters you care about, you ignore everything from that point on to the end, using (for example) a substring() method call. explore the String class and its methods for hints on how to do this sort of thing.
(i'm frankly surprised Java doesn't seem to have a configurable trim() method in String. you'd think people might want to strip off things other than whitespace often enough.)
Subhash
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |