ok please help me to understand this two things...."String" and "StringBuilder". Important point is, both are Object. In addition to that StringBuilder is not synchronized means not
thread safe. By the way, the only major thing (code wise) which differenciate these two are as follows:
For
String (creating 2 reference objects, 1 reference variable):
Note: Although JVM will create an anonymous object with value "abcdef" at line number2, but that will distroy immediately (but will remain in the memory). And therefore in line number 3 we will see the output as "abc"
For StringBuilder (creating 1 reference object, 1 reference variable) <---- I am not sure:
Note: Here, JVM will hold the memory and will modify again and again the same String object
That's how StringBuilder bits the String object. Am i right? If there is some thing more important points are missing here then please add.
On the other hand, I know that String object is immutable. But here are not we changing it's value while using StringBuilder class? Or again here that instance of Object concept is leading the floor? Can any one please help me to make this concept clear?