aspose file tools*
The moose likes Beginning Java and the fly likes String equality Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String equality" Watch "String equality" New topic
Author

String equality

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Hi,
When comparing two strings, how do you say String 1 is NOT equal to String 2? And also, when using an if statement, what type of OR do you use if you have String 1 equals String 2 OR String 2 equals String 3? TIA.
Kevin
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
The method String.equals(String) returns a boolean. So, if you have String1 and String2, it returns true if String1 equals String2, false if not.
So, to do String1 not equal to String2, you could do:
String1.equals(String2) == false
For the OR:
if ((String1.equals(String2)) | | (String2.equals(String3)))
[This message has been edited by Matt Senecal (edited September 14, 2001).]


There's nothing more dangerous than a resourceful idiot. ---Dilbert
kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
Can I do this:
if ((String1.equals(String2) == false) | | (String2.equals(String3) == false)) {
...
}
parul patidar
Ranch Hand

Joined: Sep 07, 2001
Posts: 53
When comparing two strings, how do you say String 1 is NOT equal to String 2?
if(!string1.equals(string2))
do this;
what type of OR do you use if you have String 1 equals String 2 OR String 2 equals String 3
if(string1.equals(string2)| | string2.equals(string3))
do this;
parul patidar
Ranch Hand

Joined: Sep 07, 2001
Posts: 53
Originally posted by kevin schmidt:
Can I do this:
if ((String1.equals(String2) == false) | | (String2.equals(String3) == false)) {
...
}

u want to check if string1 is equal to string2 or string2 is equal to string3 so above code will not work as it checks
if string1 is not equal to string2 or string2 is not equal to string3 seemy previous post
 
jQuery in Action, 2nd edition
 
subject: String equality