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

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).

This question is related to java if-statement equals boolean-expression

The answer is


Just put a '!' in front of the boolean expression


If the class implements comparable, you could also do

int compRes = a.compareTo(b);
if(compRes < 0 || compRes > 0)
    System.out.println("not equal");
else
    System.out.println("equal);

doesn't use a !, though not particularly useful, or readable....


if (!secondaryPassword.equals(initialPassword)) 

"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

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to if-statement

How to use *ngIf else? SQL Server IF EXISTS THEN 1 ELSE 2 What is a good practice to check if an environmental variable exists or not? Using OR operator in a jquery if statement R multiple conditions in if statement Syntax for an If statement using a boolean How to have multiple conditions for one if statement in python Ifelse statement in R with multiple conditions If strings starts with in PowerShell Multiple conditions in an IF statement in Excel VBA

Examples related to equals

this in equals method Why do we have to override the equals() method in Java? Compare two objects with .equals() and == operator Check if bash variable equals 0 Setting equal heights for div's with jQuery Java, how to compare Strings with String Arrays How can I express that two values are not equal to eachother? How to override equals method in Java How do you say not equal to in Ruby? Getting an element from a Set

Examples related to boolean-expression

'and' (boolean) vs '&' (bitwise) - Why difference in behavior with lists vs numpy arrays? Any good boolean expression simplifiers out there? if (boolean == false) vs. if (!boolean) How to make "if not true condition"? How can I express that two values are not equal to eachother? Python `if x is not None` or `if not x is None`? How to use OR condition in a JavaScript IF statement? Is this the proper way to do boolean test in SQL?