Bifalgorithm post · Computer science one · Basics
How are String variables declared and reassigned in Java?
How are String variables declared and reassigned in Java? (Computer science one · Basics) — "We can declare String variables and assign them values using the r…
Ideas in this flowchart
- String variables can be declared, assigned, and reassigned.
- String variables receive values using the regular assignment operator.
- Initial string assignments
- String firstName = "Thomas";
- String lastName = "Waits";
- A variable can be assigned a new string value.
- firstName = "Tom";
- Reassignment does not change the original string.
- The variable firstName points to a new string.
- If no other references point to the old string
- The old string becomes eligible for garbage collection.
- The JVM takes care of garbage collection.