hello, i recently encountered a problem with "!"(not) and strings. Does this work? ex. if (!(strName == "")) It doesn't give me a compiliation error. I played around with it and I think "!"(not) with strings do not work. This condition is treated as if there was no "!"(not).... Am i right? Is there an alternative way to solve this? thanks in advance.
ok, so i'm embarassed to ask this, but why would this not work? doesn't (strName == "") return a boolean? so (!(strName == "")) should just return the complement of (strName == "") granted, i've had no coffee yet this morning, but now i'm confused!!!
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Use equals() to compare the value of objects, and == to check for the same object reference. 1) String s = new String("test"); String t = new String("test"); The following hold for #1 above: s == t : false s != t : true s.equals(t) : true !s.equals(t) : false 2) String s = "test"; String t = "test"; Because of the way Java handles Strings internally, in #2 above, "s == t" may evaluate to true, but this is not something you want to count on. 3) String s = "test"; String t = s; The following would hold for #3, where you are making t point to the same object as s. s == t : true s.equals(t) : true To quote Ernest Friedman-Hill, comparing Strings with "==" is like running with scissors.
posted 16 years ago
ok thanks guys.
I brought this back from the farm where they grow the tiny ads: