String burns = "My love is like a red, red rose."; . . . . . . if ( burns.toLower().startsWith( " MY LOVE".trim().toLower() ) ) System.out.println( "Both start with the same letters." ); else System.out.println( "Prefix fails." );
What does the above write to the monitor?
Answer:
Both start with the same letters.
End of the Chapter
That was a complicated question. I hope you rose to the occasion. If you got burned, review the example. You may wish to review the following.
- An easy way to construct a String.
- The null value.
- How an object becomes garbage.
-
Stringclass description. - String concatenation.
-
Shorthand
notation
for
Stringconcatenation. - Strings as immutable objects.
-
The
trim()method. -
The
startsWith()method.