0
What is difference between ?
Allocating a variable string literal By: String a="string"; and String a =new String("string");
4 Answers
+ 4
In the 1st case it is a string literal and is directly stored in the string constant pool which is a small area on the heap.
While in the other case, an instance of String is created on the heap with the value "string" and it is pointed by "a" which is stored in the stack.
+ 1
"string" is faster.