Do a negation in an IF coding

0

I have the following condition IF :

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

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

    
asked by anonymous 21.06.2017 / 14:28

1 answer

6

If the purpose is to reverse the condition, simply 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 true or false object equality), it is never too much to remember that you should use if...else , avoiding ifs strings with inverse conditions between each other: p>

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

} else {
  //faça algo se forem diferentes
} 
    
21.06.2017 / 14:29