How to initialize a String in Java?

To initialize String in Java, just assign a String literal or a null to a variable.

All of these are valid ways to initialize a String variable:

String string1 = "Hello World!";              // some string
String string2 = new String("Hello World!");  // same as previous
String string3 = "";                          // empty string
String string4 = null;                        // null value