Completion requirements
The String class is used for text manipulation. As you read, you will learn different ways to create Strings, methods to manipulate Strings, the String concatenation operator '+', and about how Strings are immutable.
26. Cascaded String Operations
Answer:
It creates a new String
which is a lowercase version of the original string.
Cascaded String
Operations
Sometimes a method of a Cascaded String
Operations
String
creates another String
, and then a method of that second String
is invoked to create a third String
(and so on). This is sometimes called a cascade. Usually a cascade involves intermediate temporary objects. Look at these lines of code:
String burns = "My love is like a red, red rose."; . . . . . . if ( burns.toLowerCase().startsWith( " MY LOVE".trim().toLowerCase() ) ) System.out.println( "Both start with the same letters." ); else System.out.println( "Prefix fails." ); |
What is printed? Decide what string owns the startsWith
method, and then decide what parameter it is called with.
Question 26:
What does the above write to the monitor?