0

I have two strings str1 and str2. Check both of them and see if any one string is empty.

If yes, then replace that str with another one.

if(indexOf(str1) < -1 || indexOf(str2) < -1){
   str1 = str2;
 }

will this work?

1 Answer 1

5

No, that won't work for numerous reasons. This will though:

if(!str1)
    str1 = str2;
else if(!str2)
    str2 = str1;
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.