0

The main reason for asking this question is the particualr differences of how String is perceived in different languages. I am from a C++ background and now working in Java, where String is immutable. So I wanted to know the difference between

String m = "" ;

and

String n = null ;

Would be interesting to know if the pointer of m points to a memory location specially in java?

Sayantan Roy
  • 134
  • 1
  • 15

2 Answers2

0
String m = null ;

does not refer an object.

String m = "" ;

refers an object.

Mustafa Çil
  • 766
  • 8
  • 15
0

When you initialize it as "", you are assigning a value to the string. However, when you initialize it as null, it actually points to nothing but null. Eventually, string methods can be used on the first (equals, length,replaceAll,...), while you cannot use them on the second.