Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Strings are immutable
Nik Recort
Greenhorn
Posts: 26
1
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi wonderful people!
Studying
String
objects immutability I came across an example, this one:
String s1 = "1"; String s2 = s1.concat("2"); s2.concat("3"); System.out.println(s2);
The output is 12.
I understand the difference between concatenation and addition, but can you explain me why the result is 12 and not 123?
Nik Recort
Greenhorn
Posts: 26
1
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
My apologies, I have found this same topic here on the forums. I think you can delete this post.
Thanks anyway =)
Tim Cooke
Sheriff
Posts: 5555
326
I like...
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
No need to delete. Just link to the other post you found so others can get there too.
Tim Driven Development
| Test until the fear goes away
sonai kale
Ranch Hand
Posts: 65
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Java
String is immutable, String will Store the value in the form of object. String is immutable means that you cannot change the object itself, but you can change the reference to the object.
Nik Recort
Greenhorn
Posts: 26
1
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ok, thank you Tim. Here is the link
https://coderanch.com/t/667931/certification/String-Immutability-Java-OCA-Programmer
.
Have a good day =)
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Different output when string concatenaion is involved
How many String Object are created in the following code ??
casting
source code of String while using '+' and concat()
how many String objects are created
More...