Difference between null and empty ("") Java String

Vikas Patidar picture Vikas Patidar · Jan 26, 2011 · Viewed 406.8k times · Source

What is the difference between null and the "" (empty string)?

I have written some simple code:

String a = "";
String b = null;

System.out.println(a == b); // false
System.out.println(a.equals(b)); // false

Both statements return false. It seems, I am not able to find what is the actual difference between them.

Answer

mikiqex picture mikiqex · Aug 21, 2017

You may also understand the difference between null and an empty string this way:

Difference between null and 0/empty string

Original image by R. Sato (@raysato)