Hi, For this you will need to understand that String is immutable. It maintains a pool of literal strings and simply refers to that. When someone changes the string value, it will abandon that literal, create a new literal and will start referncing it. When u simply say x="Mother" it just references any "Mother" in the pool, if not it will create a new "Mother" and refer it. But when you say "new", you are effectively forcing the JVM to refer to a new literal whether an equivalent literal exists in the pool or not (which actually is a waste of memory) Regards, Sanju
This thread has been viewed 616 times.
All times above are in ranch (not your local) time.
The current ranch time is Sep 21, 2018 23:13:54.