go to previous page   go to home page   go to next page

Is this statement:

String outString = null;

the same as this statement:

String outString = ""; // the string consisting of no characters


No. The first statement assigns the null value to a reference variable. The second creates a String object which contains no characters and assigns its reference to the variable. This is necessary because later in the program the String object's concatenation method is used to create a new object:

outString += caps ;

The trim() Method

The trim() method removes whitespace from both ends of its string. White space consists of spaces and tabs. For example,

"  Both Sides Now   ".trim()

evaluates to

"Both Sides Now"

Notice that interior whitespace is not removed.

Details: In fact, trim() removes from both ends of the string all characters that occur up to and including the space character in the unicode sequence of characters. Since the space character has the code \u0020 this means that characters with a code less than that are removed from both ends of the string. This includes tabs and other non-printing characters.


Puzzle: What does the following evaluate to?

"      ".trim()