Forums Register Login

String constant pool

+Pie Number of slices to send: Send
why output is unequal.
class Pool
{
public static void main(String[] ar)
{
String s="abc";
String s1="ab";
s1=s1+"c";//why s1 is not created in pool this is also literal
if(s==s1)
System.out.println("equal");
else
System.out.println("unequal");
}
}
+Pie Number of slices to send: Send
Always use code tags:



Better now. Isn't it? When you say

, do you know what happens? Or let me put it this way, how many String objects are out there?
+Pie Number of slices to send: Send
 

Ritesh raushan wrote:s1=s1+"c";//why s1 is not created in pool this is also literal...


"c" might be a literal, but 's1 + "c"' is not; that's why.

And in fact "c" WILL be put into the pool as a result of that statement (at least, I'm pretty sure it will; you can test it).

Winston
+Pie Number of slices to send: Send
 

Winston Gutkowski wrote:

Ritesh raushan wrote:s1=s1+"c";//why s1 is not created in pool this is also literal...


"c" might be a literal, but 's1 + "c"' is not; that's why.

And in fact "c" WILL be put into the pool as a result of that statement (at least, I'm pretty sure it will; you can test it).

Winston



You gave it away Winston. I wanted to get it out of him. Anyways, its done now.
rubbery bacon. rubbery tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 718 times.
Similar Threads
JQPLUS question
Doubt About Strings
String Comparision
Confusion on the topic of String constant table ?
String Pooling & String Constructors
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:08:16.