How to check if a String is null in Java?

To check if a String is null in Java, do this: string == null.

Here's how you do it:

String firstString = "Hello World!";
String secondString = null;

// does nothing…
if (firstString == null) {
  System.out.println("First string is null!");
}

// prints: Second string is null!
if (secondString == null) {
  System.out.println("Second string is null!");
}