Forums Register Login

reinitializing a String variable

+Pie Number of slices to send: Send
Shouldn't the code I have written work so far as the cm_pageName getting reset to HOME or LIST ?
What am I doing wrong in resetting cm_pageName?





I am just getting blank values and I have tested the value of cm_pageName to be one of the 2 strings shown.

Thanks,
Dan
+Pie Number of slices to send: Send
Never use == for String comparison - use the equals method instead.
+Pie Number of slices to send: Send
Thanks a lot~

Looks like this for the record.

+Pie Number of slices to send: Send
== is used to compare the values of primitive typed variables and the memory location of Objects.
equals is used to compare the content of the two objects.

== is normally much faster than equals since it just checks the memory location of two objects.
+Pie Number of slices to send: Send
Oh I see.. and since String is not a primitive variable type, the equals method is better.
+Pie Number of slices to send: Send
 

Dan Acuff wrote:Oh I see.. and since String is not a primitive variable type, the equals method is better.


That's correct. And using == to compare Strings is a little more complicated than with most objects because of the String pool. See Strings Literally.
+Pie Number of slices to send: Send
On line 2 there is no reason to create a new string.
Lookout! Runaway whale! Hide behind this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1027 times.
Similar Threads
How do we spot what will cause a NullPointerException?
File Creation Problem in unix
Arrays.asList()
java.Lang.classCastException
NullPointerException... what is left to check?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:57:37.