String data = new String("Turtle"); data = data + 's' ;
Yes.
The last statement constructs a new String,
that contains the characters "Turtles",
and places a reference to the new String in the
reference variable data
.
Strings objects are immutable. Once a String has been constructed, it never can be changed. This has many advantages in making programs understandable and reliable. For example, if a method has a reference to a String, that String will always contain the same characters, no matter what other methods are called and what they do.
For this reason, a program that does only moderate amounts
character of character manipulation should do it all using
class String.
However, constantly creating new String
objects
and garbage collecting the old objects takes up significant time.