And work the rest out for yourselves.>
campbell@computer:~/java$ java StringEqualsDemo Campbell
s = Campbell, hash = fb83cb24, s1 = Campbell, . . .
Jesper de Jong wrote:
Jd Sierra wrote:
This is not valid Java syntax. Did you mean:
Ankur Kapoor wrote:
2. Now lets take a scenario where you would have used new String() pre String literal created in a POOL
String myString = new String("fun"); // this shall create a New Object in HEAP but not in POOL . [OBJECT CREATED] hence creating only single Object that is in HEAP
3. Now let's use intern() function of String to make the String Objects created using new operator available in the POOL
String myString = new String("fun").intern() // this shall create a New Object in HEAP and also place it in the POOL . [OBJECT CREATED]
Kathy Sierra wrote:
In this case, because we used the new keyword, Java will create a new String object in normal (nonpool) memory, and s will refer to it. In addition, literal "abc" will be placed in the pool.
Jd Sierra wrote:
now I want to know is how many object will be created in this case just and only because of line no.2?
After the end of first line, one object will be created as I mentioned in case 1.
Because of 2nd line, definately one object will be created containing String literal "ghi" due to new keyword which will not be referred from Strin Literal Pool Table. But I think here unlike in case 2, one more object containg String literal "ghi" will not be created which we are passing in String constructor because it's alreday available after line 1.
So, answer is only one new object is created just and only because of line no.2
fred rosenberger wrote:2) ANY and EVERY time the compiler sees a String literal for the first time, a String is created in the String pool.
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earthhttps://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter