Answer:
class ImmDemo
{
public static void main ( String[] args )
{
String str = new String("I recognize the vestiges of an old flame.");
str = str.substring( 16 );
System.out.println( str );
}
}
"Changing" a String
A common mistake is to think "make a change" to a string, but to then attempt to change an immutable object. When you think "make a change" you need to do two things:
- Compute a new
Stringobject. - Assign the reference to the new string to a reference variable.
The diagram shows how the second version of the program works.
The reference variable str is first assigned a reference to
the original object.
Then a new object is constructed by substring().
The new reference is assigned to str.
println() is called with the new reference, so the new string is written.
QUESTION 3:
Which character corresponds to index 0 in the following string?
I recognize the vestiges of an old flame.