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.
14. The trim() Method
Answer:
13
Don't forget to count the space.
The trim()
Method
trim()
Method
Here is a line of the documentation for the String
class.
public String trim();
The trim()
method of a String
object creates a new String
that is the same as the original except that any leading or trailing space is trimmed off (removed).
Question 14:
Examine the following code:
String userData = " 745 "; String fixed; fixed = userData.trim();
Has the
trim()
method been used correctly? How many objects have been created?