Skip to main content
3 of 3
edited title
Tulains Córdova
  • 39.5k
  • 13
  • 99
  • 155

Java: difference between String a = null and String a = new String()

It's a pretty naive question to ask but I got this doubt while programming for Android. I use to initialize my new strings like String a=null, so in my code there remains a probability to get NullPointerException if I forget to initialize the variable before accessing it but what about the other case. Also which one should be used?

Rajat Saxena
  • 121
  • 1
  • 1
  • 7