String stringG = new String("And yet, it moves!");
Yes.
String
Many methods of a String
object create another String
object.
For example,
the substring(int begin)
String
that contains a copy of
part of the original data.
Here is a program that uses this method:
class StringDemo3 { public static void main ( String[] args ) { String str = new String( "Golf is a good walk spoiled." ); // create the original object String sub = str.substring(8); //create a new object from the original System.out.println( sub ); } }
The clause
str.substring(8)
creates a new String
object,
that contains its own data,
which are characters copied from the original string.
The copy starts with the 8th character of the original string
and continues to the end.
Character numbering starts at zero, so
the 8th character in the original string is the first 'a'.
The substring of the original string is contained in a new String
object.
A reference to that new string is assigned to the reference variable sub
.
What characters are contained in the new object?