performance - What is the runtime difference of using the string initialization in java? -


i need know difference of initializing string in java when using runtime.

for exmaple:

string declare = null; 

otherwise:

string declare = ""; 

i declared 2 type of declaration of string. 1 best runtime declaration.

a string object. if initialize null, telling compiler aware wasn't initialized, , there should no warnings when first try use variable. aside that, pointing reference null, of course.

if initialize string empty string, however, following happens:

  • there's string object allocated
  • the compiler put string literal in string pool
  • any other string initialize "" point same inmutable string pool

so, question is, how handle nulls or empty strings in code? that's should guide decision


Comments