Originally posted by Bikash Paul:
My guess is when we are concating may be compiler creating String object in normal memory(non-pool).
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ajay S:
String a = "ab" + "c";
this internally uses StringBuffer (or StringBuilder for newer JVMs)
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Not correct. The compiler is intelligent enough to see that "ab" + "c" is a "constant expression" and calculates it value at compile
time. Therefore in this case the String "abc" would actually be put into the constant pool!
this
String x = "ab" + "c";
doesn't keep x on the pool.
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
Originally posted by Bikash Paul:
Is that right?
Originally posted by Bikash Paul:
Jim,
That means when we use str1 = str1.concat("c") it's cretaing String object in normal memory(non-pool) thats why it's returning false. Is that right?
Thanks
Bikash
When you are calling the concat method, the compiler won't do any concatenation, it just will generate the byte code for the method call. The actual concatenation than happens at runtime. And the last line in String.concat is
return new String(0, count + otherLen, buf);
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|