• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String equality

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I do this:
if ((String1.equals(String2) == false) | | (String2.equals(String3) == false)) {
...
}
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic