0
String s=new String("somnath");
how many object will it create and why Or how?
4 Réponses
+ 5
There comes a term 'string pool'. think of it as a notebook where string called are written.
When we use double quotes to create a String, it first looks for String with same value in the String pool, if found it just returns the reference else it creates a new String in the pool and then returns the reference.
However using new operator, we force String class to create a new String object in heap space. This means that the same thing will be written two times
in the string pool or the virtual 'notebook'. This causes waste of memory and the first method is recommended.
+ 2
I could not understand what you are trying to ask this time :-(
please elaborate.
0
for the first time? after that 1 object ?
0
https://code.sololearn.com/cZzTT3H09obg/?ref=app
I'm sure this code I've written will help u understand more clearly