How can I express that two values are not equal to eachother?

cdo picture cdo · Dec 3, 2011 · Viewed 158.7k times · Source

Is there a method similar to equals() that expresses "not equal to"?

An example of what I am trying to accomplish is below:

if (secondaryPassword.equals(initialPassword)) 
{
    JOptionPane.showMessageDialog(null, "You've successfully completed the program.");
} else {
    secondaryPassword = JOptionPane.showInputDialog(null, "Your passwords do not match. Please enter you password again."); 
}

I am trying to find something that will not require me to use if ( a != c).

Answer

Anthony Pegram picture Anthony Pegram · Dec 3, 2011

"Not equals" can be expressed with the "not" operator ! and the standard .equals.

if (a.equals(b)) // a equals b
if (!a.equals(b)) // a not equal to b