| Author |
How do I get Not Equals?
|
Amy Phillips
Ranch Hand
Joined: Apr 02, 2003
Posts: 280
|
|
|
Ok I understand the equals() but is there a way to check if your string is not equal to something? I take it theres a ! or a false in there somewhere....
|
 |
Susilo Saja
Ranch Hand
Joined: May 27, 2003
Posts: 91
|
|
yes u can use "!" or "== false" example: String s1 = "hi"; String s2 = "he"; if (!s1.equals(s2)) { }
|
 |
Susilo Saja
Ranch Hand
Joined: May 27, 2003
Posts: 91
|
|
Sorry I accidentally click submit before I could finish. Below is my complete reply. yes u can use "!" or "== false" example: String s1 = "hi"; String s2 = "he"; if (!s1.equals(s2)) { //will go here } s1.equals(s2) will return false, and the use of "!" operator is to revert the boolean value (if it's true, it will become false, and the opposite way). So, !s1.equals(s2) will return true. The other way is: if (s1.equals(s2) == false) { //will go here }
|
 |
Francis Siu
Ranch Hand
Joined: Jan 04, 2003
Posts: 867
|
|
hi Amy There are uncountable combinations Susilo said a part of it. String s1 = "hi"; String s2 = "he"; if (s1.equals(s2) == false) if (!s1.equals(s2)) And a part of the following is the sample one. if(!s2.equal(s1)!=false) if(s2.equals(s1))!=true) if (s1!=s2) if((s1!=s2)!=false) if ((s1==s2)==false) if(!(s1==s2)) But you should notice the different between each other hope this help not confuse
|
Francis Siu
SCJP, MCDBA
|
 |
Amy Phillips
Ranch Hand
Joined: Apr 02, 2003
Posts: 280
|
|
Thanks you two thats cleared it up for me
|
 |
 |
|
|
subject: How do I get Not Equals?
|
|
|