Lets break it into some parts
String s1 = “hello”;
This Statement creates string containing hello and occupy space in memory i.e. in Constant String Pool and and assigned it to reference object s1
String s2 = s1;
This statement assigns the same string hello to new reference s2
_______
| |
s1 ---->| hello |<----- s2
|_______|
Both references are pointing to the same string so output the same value as follows.
out.println(s1); // o/p: hello
out.println(s2); // o/p: hello
Though String is immutable, assignment can be possible so the s1 will now refer to new value stack.
s1 = “stack”;
_________
| |
s1 ---->| stack |
|_________|
But what about s2 object which is pointing to hello it will be as it is.
__________
| |
s2 ---->| hello |
|__________|
out.println(s1); // o/p: stack
out.println(s2); // o/p: hello
Since String is immutable Java Virtual Machine won’t allow us to modify string s1 by its method. It will create all new String object in pool as follows.
s1.concat(” overflow”);
___________________
| |
s1.concat ----> | stack overflow |
|___________________|
out.println(s1); // o/p: stack
out.println(s2); // o/p: hello
out.println(s1.concat); // o/p: stack overflow
Note if String would be mutable then the output would have been
out.println(s1); // o/p: stack overflow
Now you might be surprised why String has such methods like concat() to modify. Following snippet will clear your confusion.
s1 = s1.concat(” overflow”);
Here we are assigning modified value of string back to s1 reference.
___________________
| |
s1 ---->| stack overflow |
|___________________|
out.println(s1); // o/p: stack overflow
out.println(s2); // o/p: hello
That’s why Java decided String to be a final class Otherwise anyone can modify and change the value of string. Hope this will help little bit.
химчистка обуви отзывы химчистка обуви цена
Your article helped me a lot, is there any more related content? Thanks!
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
seogrowth site – Content reads clearly, helpful examples made concepts easy to grasp.
leadnex site – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
nicheninja site – Bookmarked this immediately, planning to revisit for updates and inspiration.
reachly site – Color palette felt calming, nothing distracting, just focused, thoughtful design.
leadzo site – Found practical insights today; sharing this article with colleagues later.
leadora site – Bookmarked this immediately, planning to revisit for updates and inspiration.
traffio site – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
adster – Color palette felt calming, nothing distracting, just focused, thoughtful design.
reacho – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
offerorbit – Loved the layout today; clean, simple, and genuinely user-friendly overall.
promova – Appreciate the typography choices; comfortable spacing improved my reading experience.
rankora – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
trendfunnel – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
scaleify – Found practical insights today; sharing this article with colleagues later.
stackhq – Appreciate the typography choices; comfortable spacing improved my reading experience.
bytehq – Appreciate the typography choices; comfortable spacing improved my reading experience.
cloudhq – Loved the layout today; clean, simple, and genuinely user-friendly overall.
devopsly – Content reads clearly, helpful examples made concepts easy to grasp.
stackops – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
kubeops – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
cloudopsly – Appreciate the typography choices; comfortable spacing improved my reading experience.
keywordcraft – Loved the layout today; clean, simple, and genuinely user-friendly overall.
adscatalyst – Appreciate the typography choices; comfortable spacing improved my reading experience.
promoseeder – Content reads clearly, helpful examples made concepts easy to grasp.
clickrevamp – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
serpstudio – Navigation felt smooth, found everything quickly without any confusing steps.
leadspike – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
trafficcrafter – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
auditpilot – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
leadvero – Navigation felt smooth, found everything quickly without any confusing steps.
authoritylab – Color palette felt calming, nothing distracting, just focused, thoughtful design.
datadev – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
applabs – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
dataops – Loved the layout today; clean, simple, and genuinely user-friendly overall.
trycloudy – Color palette felt calming, nothing distracting, just focused, thoughtful design.
gobyte – Bookmarked this immediately, planning to revisit for updates and inspiration.
getbyte – Color palette felt calming, nothing distracting, just focused, thoughtful design.
usebyte – Found practical insights today; sharing this article with colleagues later.
getkube – Color palette felt calming, nothing distracting, just focused, thoughtful design.
trystack – Navigation felt smooth, found everything quickly without any confusing steps.
usekube – Found practical insights today; sharing this article with colleagues later.
getstackr – Bookmarked this immediately, planning to revisit for updates and inspiration.
usestackr – Loved the layout today; clean, simple, and genuinely user-friendly overall.
cloudster – Content reads clearly, helpful examples made concepts easy to grasp.
deployly – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
byteworks – Bookmarked this immediately, planning to revisit for updates and inspiration.
stackable – Appreciate the typography choices; comfortable spacing improved my reading experience.
datavio – Content reads clearly, helpful examples made concepts easy to grasp.
devnex – Bookmarked this immediately, planning to revisit for updates and inspiration.
bytevia – Bookmarked this immediately, planning to revisit for updates and inspiration.
dataworks – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
cryptora – Navigation felt smooth, found everything quickly without any confusing steps.
kubexa – Content reads clearly, helpful examples made concepts easy to grasp.
stackora – Found practical insights today; sharing this article with colleagues later.
cloudiva – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
netlance – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
devonic – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
apponic – Navigation felt smooth, found everything quickly without any confusing steps.
codefuse – Found practical insights today; sharing this article with colleagues later.
codepushr – Bookmarked this immediately, planning to revisit for updates and inspiration.
mergekit – Appreciate the typography choices; comfortable spacing improved my reading experience.
shipkit – Navigation felt smooth, found everything quickly without any confusing steps.
debugkit – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
commitkit – Loved the layout today; clean, simple, and genuinely user-friendly overall.
testkit – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
deploykit – Color palette felt calming, nothing distracting, just focused, thoughtful design.
logkit – Appreciate the typography choices; comfortable spacing improved my reading experience.
flowbot – Found practical insights today; sharing this article with colleagues later.
promptkit – Content reads clearly, helpful examples made concepts easy to grasp.
modelops – Color palette felt calming, nothing distracting, just focused, thoughtful design.
databrain – Content reads clearly, helpful examples made concepts easy to grasp.
smartpipe – Navigation felt smooth, found everything quickly without any confusing steps.
opsbrain – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
guardstack – Content reads clearly, helpful examples made concepts easy to grasp.
securekit – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
authkit – Navigation felt smooth, found everything quickly without any confusing steps.
pipelinesy – Color palette felt calming, nothing distracting, just focused, thoughtful design.
zerotrusty – Found practical insights today; sharing this article with colleagues later.
auditkit – Navigation felt smooth, found everything quickly without any confusing steps.
keyvaulty – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
shieldops – Color palette felt calming, nothing distracting, just focused, thoughtful design.
secstackr – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
techsphere – Color palette felt calming, nothing distracting, just focused, thoughtful design.
cyberstack – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
nanotechhub – Bookmarked this immediately, planning to revisit for updates and inspiration.
keyvaulty – Found practical insights today; sharing this article with colleagues later.
clicktechy – Content reads clearly, helpful examples made concepts easy to grasp.
bytetap – Content reads clearly, helpful examples made concepts easy to grasp.
quickbyte – Found practical insights today; sharing this article with colleagues later.
techvertex – Bookmarked this immediately, planning to revisit for updates and inspiration.
pixelengine – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
futurestack – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
logicforge – Found practical insights today; sharing this article with colleagues later.
bytelab – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
zyrotech – Navigation felt smooth, found everything quickly without any confusing steps.
omegabyte – Appreciate the typography choices; comfortable spacing improved my reading experience.
techdock – Color palette felt calming, nothing distracting, just focused, thoughtful design.
codehive – Content reads clearly, helpful examples made concepts easy to grasp.
futurebyte – Content reads clearly, helpful examples made concepts easy to grasp.
codenova – Bookmarked this immediately, planning to revisit for updates and inspiration.
bytenova – Navigation felt smooth, found everything quickly without any confusing steps.
zybertech – Navigation felt smooth, found everything quickly without any confusing steps.
zenixtech – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
technexus – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
veloxtech – Appreciate the typography choices; comfortable spacing improved my reading experience.
byterise – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
techcatalyst – Found practical insights today; sharing this article with colleagues later.
dataforge – Content reads clearly, helpful examples made concepts easy to grasp.
logicbyte – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
binaryforge – Content reads clearly, helpful examples made concepts easy to grasp.
seoshift – Loved the layout today; clean, simple, and genuinely user-friendly overall.
clickrly – Navigation felt smooth, found everything quickly without any confusing steps.
seoradar – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
reachrocket – Navigation felt smooth, found everything quickly without any confusing steps.
convertcraft – Content reads clearly, helpful examples made concepts easy to grasp.
boostsignals – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
ranktarget – Appreciate the typography choices; comfortable spacing improved my reading experience.
searchmetrics – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
searchsignals – Content reads clearly, helpful examples made concepts easy to grasp.
rankstrategy – Appreciate the typography choices; comfortable spacing improved my reading experience.
adzio – Found practical insights today; sharing this article with colleagues later.
devwave – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
cybernexus – Bookmarked this immediately, planning to revisit for updates and inspiration.
nexonbyte – Mobile version looks perfect; no glitches, fast scrolling, crisp text.
zentrotech – Found practical insights today; sharing this article with colleagues later.
vynextech – Content reads clearly, helpful examples made concepts easy to grasp.
zylotech – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.
bytecraft – Bookmarked this immediately, planning to revisit for updates and inspiration.
growthmarketing – Found practical insights today; sharing this article with colleagues later.
convertio – Pages loaded fast, images appeared sharp, and formatting stayed consistent.
signaltrack – Content reads clearly, helpful examples made concepts easy to grasp.
admark – Navigation felt smooth, found everything quickly without any confusing steps.
btcusa – Loved the layout today; clean, simple, and genuinely user-friendly overall.
reachriver – Color palette felt calming, nothing distracting, just focused, thoughtful design.