How to check if two strings are not equal in Java?

To check if two strings are not equal in Java, do this: !string1.equals(string2).

Here's how you do it:

String string1 = "Hello";
String string2 = "World";
String string3 = "Hello";

if (!string1.equals(string2)) {
  System.out.println("1) This will print!");
}

if (!string1.equals(string3)) {
  System.out.println("2) This will not print!");
}