0

I want to perform the same operation for more than one value of a string called contents

if (contents == "chicken roll" , contents == toasted chicken){
      // do some common operation
    }

What is the proper Java syntax for this?

3
  • 1
    what you wrote has no sense at all... do you mean "if contents is 'chicken roll' or contents is 'toasted chicken'" ? or do you mean "if contents is 'chicken roll' and contents is 'toasted chicken'" ? and by the way, do you consider "contents" being something like a collection of "things related to chicken" or contents is one chicken (i.e. "if 'chicken roll' is in contents or 'toasted chicken' is in contents")? Commented Sep 8, 2012 at 19:05
  • See boolean operators Commented Sep 8, 2012 at 19:06
  • @zmo: Since the title is "if something = something or something", I guess he means "or". Commented Sep 8, 2012 at 19:09

1 Answer 1

2

I think you want a logical or ||:

if (contents.equals("chicken roll") || contents.equals("toasted chicken")){

See the list of operators.

Also note that you compare for string equality using the equals method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.