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

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

Question Protected by gnat
added 4 characters in body
Source Link
Tulains Córdova
  • 39.5k
  • 13
  • 99
  • 155

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

It 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?

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?

Source Link
Rajat Saxena
  • 121
  • 1
  • 1
  • 7

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

It 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?