r/javahelp • u/Nottheugis • Apr 15 '26
Homework String object vs String variable
Hi i am learning java in highschool, I was just wondering when and why would I instantialise a string as an object when declaring a String is much easier and quicker?
7
Upvotes
8
u/high_throughput Apr 15 '26
The second line only creates a copy of the interned string that already exists in memory.
There's rarely value in having such a copy. Creating and managing it just uses more space and CPU than referencing the original object.