Yesterday I was working on an android project & found that null
value too is concatenated to a String also it effects the String length , while empty string doesn't have any effect.
Why is it so ?
UPDATED QUESTION : Why is it so ? null is supposed to hold nothing !
import java.util.*;
import java.lang.*;
import java.io.*;
class Sample
{
public static void main (String[] args)
{
String nullVar = null;
String emptyVar = "";
String newNullVar = nullVar + "Some,String";
String newEmptyVar = emptyVar + "Some,String";
System.out.println(newNullVar + " & length is " +newNullVar.length());
System.out.println(newEmptyVar + " & length is " +newEmptyVar.length());
}
}
OUTPUT :
nullSome,String & length is 15
Some,String & length is 11