Results 1 to 6 of 6
  1. #1
    cagipple is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default string operators

    Hello.

    Is there an "or" operator when comparing two strings. I know you can use "||" when dealing with integers, but how do I do this for strings?

    For example:

    (string1.equals(string2) OR (string3));

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You're thinking about this wrong. You don't OR Strings or AND Strings, you do these things to booleans. So you'd do

    Java Code:
    if (string1.equals(string2) || string1.equals(string3)) {
       //...

  3. #3
    cagipple is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default

    Okay, but I'm trying to put this in a do while loop as an expression. I get a syntax error when I do what you said.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by cagipple View Post
    Okay, but I'm trying to put this in a do while loop as an expression. I get a syntax error when I do what you said.
    There's no way we can help you and guess what your error is if you don't show the code and the error message both. This should be obvious.

  5. #5
    cagipple is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default

    Nevermind fixed it. Stupid mistake. Thank you for your help.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by cagipple View Post
    Nevermind fixed it. Stupid mistake. Thank you for your help.
    Glad you've got it fixed.

Similar Threads

  1. where exactly bit shift operators are useful?
    By sandeepsai39 in forum New To Java
    Replies: 6
    Last Post: 09-08-2010, 12:58 PM
  2. New to operators, need some help...
    By Stryker4526 in forum New To Java
    Replies: 4
    Last Post: 09-26-2009, 02:29 AM
  3. Java Operators
    By Ash-infinity in forum New To Java
    Replies: 6
    Last Post: 12-02-2008, 12:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •