Concept

How are String variables declared and reassigned in Java?

ComputerScienceOne / Basics

"We can declare String variables and assign them values using the regular assignment operator.\n\n1 String firstName = \"Thomas\";\n\n2 String lastName = \"Waits\";\n\n3 4 //we can also reassign values\n\n5 firstName = \"Tom\";\n\nNote that the reassignment in the last line in the example does not change the original string. It just makes the variable firstName point to a new string. If there are no other references to the old string, it becomes eligible for garbage collection and the JVM takes care of it."

Related Ideas