String dryden = "   None but the brave deserves the fair.   " ;
System.out.println( dryden.trim() );
What is printed out?

A good answer might be:

None but the brave deserves the fair.
(There are no printed spaces on either side of the above. The internal spaces remain.)

Control Characters inside String Objects

The characters that a String object contains can include control characters. For example, examine the following code:

class beautyShock
{
  public static void main (String[] arg)
  {
    String line1 = "Only to the wanderer comes\n";
    String line2 = "Ever new this shock of beauty\n";

    String poem  = line1 + line2;

    System.out.print( poem );
  }
}    

The sequence \n represents the control characters that ask for a new line on the monitor. These control characters will be part of the data contained in the object referenced by poem. When the program is run, it will write to the monitor:

Only to the wanderer comes
Ever new this shock of beauty

Although you do not see them printed, the control characters are part of the data in the String. Here is another method from the String class:

public String toLowerCase();

This method constructs a new String object containing all lower case letters.

QUESTION 12:

Here are some lines of code. Which ones are correct?

Line of code: OK Not Ok
String line = "The Sky was like a WaterDrop" ;    
String a = line.toLowerCase();    
String b = toLowerCase( line );    
String c = toLowerCase( "IN THE SHADOW OF A THORN");    
String d = "Clear, Tranquil, Beautiful".toLowerCase();    
System.out.println( "Dark, forlorn...".toLowerCase() );    
Click Here after you have answered the question