java - Appending the string -
Can someone understand the difference between the implementation of the string
1)
{string coma = ","; Last return STR = "hello" + comma + "welcome" + comma + "" + + comma + "pile" + comma + "overflow"; }
2)
{return finalStr = "Hello, welcome, stack, overflow"; }
How many string objects will be created in the first (1) block, there will be only one string finalStr
which shows the memory location where H Ello Welcome, in, stack, overflow is stored or will create many places for each word, and then adding it once will create a new memory spot.
In both cases, only one string object will be created for each, since compiler compiles in combination Is smart enough to understand. These are string literals, their compilation will be assessed on time and only one string will be created for each case. According to
A long string can literally be broken, written in small pieces using string conjunction operator + [...] and (possibly : Cursressisised) is written as an expression [...] Also, the string literally always refers to the same frequency of class string.
- String is calculated by continuous expression (§15.28), calculated at the time of compilation, and after that it is considered as if it were written.
- The string made by concatenation on run-time is newly created and therefore different.
Comments
Post a Comment