Make a denial in an IF codition

Asked

Viewed 585 times

0

I have the following condition IF:

(ClientesBDM.getNomeEmpresa().toString().equals(ClientesBD.get(1).toString()))

How can I verify if the variables are different, ie deny this condition in the same IF

  • You want to reverse the equals condition, that’s it?

  • Do you know the logical negation operator? The operator !

1 answer

6


If the goal is to reverse the condition, just use the negation operator at the beginning:

if(!ClientesBDM.getNomeEmpresa().toString().equals(ClientesBD.get(1).toString())) {
  //faça algo caso sejam diferentes

}

However, if you need to do some action in both situations (be it the equality of true or false objects), it is never too much to remember that you should use if...else, avoiding chains of ifs with inverse conditions among themselves:

if(ClientesBDM.getNomeEmpresa().toString().equals(ClientesBD.get(1).toString())) {
      //faça algo caso sejam iguais

} else {
  //faça algo se forem diferentes
} 
  • Perfect, was exactly deny my condition I needed, so release I already mark as accept the question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.