according to my understanding when u create String x="xyz"..then any matches to this literal "xyz" in the String pool is found out..if any match is found...then it is reffered by variable x...therefore here new object is not created....when we performed the concatenation in the later step....new object is created and is reffered back to variable x....hence only one object is created...this is only a guess...waiting for the correct answer...... wats the ans...
How many objects of String are created? string x="xyz"; x=x+"pqr"; tHANKS
Since Strings are immutable , Of total three Obj's are created. 1 -> "xyz" ; even though it exists in memory, it is considered lost after reassigning to 'x'. 2-> "xyzpqr" 3-> "pqr" itself is one object. Plz suggest, if I'm wrong.
i think 3 objects will be created 2 in pool and one not in pool x="xyz"; creates a string object "xyz" in pool x=x+"pqr";it creates a string object "pqr" in pool and since value of variable x is evaluated at runtime the new string object "xyzpqr" will be created outside of pool
The result of this code fragment is �spring winter spring summer�. There are two reference variables, s1 and s2. There were a total of eight String objects created as follows: �spring�, �summer � (lost), �spring summer�, �fall� (lost), �spring fall� (lost), �spring summer spring� (lost), �winter� (lost), �spring winter� (at this point �spring� is lost). Only two of the eight String objects are not lost in this process.