I cannot understand the following StringBuilder behavior when NULL objects are added to an instance:
public class StringBufferTest {
public static void main(String[] args) {
String nullOb = null;
StringBuilder lsb = new StringBuilder();
lsb.append("Hello World");
System.out.println("Length is: " + lsb.length());
lsb.setLength(0);
System.out.println("Before assigning null" + lsb.length());
lsb.append(nullOb);
System.out.println("Length now is:" + lsb.length());
}
}
The last print statement does not print 0. Can someone help me understand the behavior?
source
share