Using a String literal, such as "abc", will cause a new entry to be created in the String literal pool. (Makes sense, right? String literals go into the String literal pool.
)
However, when you invoke a method such as toLowerCase(), which returns a new Sting, we create a brand new String object on the heap - not in the String literal pool.
If you wanted to optimize your code, you could do this:
Theintern method will check the String literal pool and determine if an identical String already exists. If it does, a reference to that String object is returned so that this one (which is on the heap) can be garbage collected.
However, none of this is on the
SCJP exam.