If you pass a null, the string "null" is appended to or inserted in the existing StringBuilder. No NullPointerException is thrown.
=============
Code: Select all
StringBuilder str = new StringBuilder("Hello");
str.append(null);
============
Then i tried this one .
Code: Select all
String str1 = null;
StringBuilder str = new StringBuilder("Hello ");
str.append(str1);
System.out.println(str);
And it printed: Hello null
======================
Is it because if i directly pass a null , it has no way of knowing what the type of object being passed is ?