+ 1
What's the difference between an empty string and a null string? And both of them will have an address in the memory?
2 Respuestas
+ 2
String s="" ;
Will reference to empty string.
String s=null;
will not point to any reference.
Edit:
For differences run this..
public class Program
{
public static void main(String[] args) {
String s=null;
String ss="";
System.out.println(s instanceof String);
System.out.println(ss instanceof String);
if(s==null)
System.out.println(""+null);
if(ss!=null)
System.out.println("not null"+ss);
if(s==ss)
System.out.println("same");
else
System.out.println("not same");
if(ss.equals(s))
System.out.println("same value");
}
}
//s. equals(ss) gives null pointer exception..
0
Thanks for this detailed answer😊