posted 17 years ago
3.
Strings, and specifically string literals, are handled differently from other objects.
any time you have a new string literal (something in quotes that hasn't been seen before), it is created as a String object in the String Pool.
so, the fact that you have "abc" creates a String object in the pool. having the same literal still gives one object in the pool, so the second "abc" does not create a second String object.
Then, each call of "new StringBuffer()" will give you another object. so, you have the String "abc", and two StringBuffers, each of which has a value of "abc".
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors