String str=null;
String str=" "; and
String str="";
The second and third initialization set str to an actual string value. The string in
the second initializer contains a single space character. The string in the third
initializer is emty.
The first initializer set the str reference to the value null, i.e. str doesn't refer to a
string value.
Difference between String x=null;String x="";String x=" " is as follows,
a) In third initialization, String with "blank space" is assigned to String x;
b) In First initialization, null is a condition where the variable (a reference pointer) is completely empty. It is not pointing to any object at all.
c) In second initialization, empty string is asigned to String x;
A empty string is where there is a String object, but its contents have zero length, there is nothing in it.
Comment