• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I get Not Equals?

 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes u can use "!" or "== false"
example:
String s1 = "hi";
String s2 = "he";
if (!s1.equals(s2)) {
}
 
Susilo Saja
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you two thats cleared it up for me
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic