public static void main(String[] args) {
String s="";
String s1=null;
String s2="null";
for(int i=0;i<2;i++) {
s+=i;
s1+=i;
s2+=i;
}
System.out.println(s);
System.out.println(s1);
System.out.println(s2);
}
I understand why an empty string will give 01 as a result. But I don't understand why s1 and s2 values will be the same. While s1 is null and s2 has null as a string value. Still, they give the same answer.
null, and that refers to "String Conversion" in the JLS: docs.oracle.com/javase/specs/jls/se10/html/… "If the reference is null, it is converted to the string "null" (four ASCII characters n, u, l, l)."