Click here to Skip to main content
15,894,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
String a="abc";
String b="xyz";
String c=a+b;
Posted
Updated 27-Jun-15 7:19am
v2

1 solution

In all cases you described, new piece of memory is allocated for new string object.

But this does not happen in all cases. To understand different cases of memory allocation, you have to understand two facts: 1) Java strings are immutable objects, 2) string interning is used.

Please see:
https://en.wikipedia.org/wiki/String_interning[^],
http://javatechniques.com/blog/string-equality-and-interning[^].

By the way, look at this interesting answers to the questions not directly related to yours:


—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900