Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java String trim() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ myStr = " Hello World! ";3Order
Put the learning moves in the order that makes the concept easiest to apply.
The trim() method removes whitespace from both ends of a string.
Definition and Usage
Java String trim() Method
❮ String Methods
Example
String myStr = " Hello World! ";
System.out.println(myStr);
System.out.println(myStr.trim());Definition and Usage
The trim() method removes whitespace from both ends of a string.
Note
This method does not change the original string.
Syntax
public String trim()Parameters
None.
Technical Details
| Returns: | A String value, which is a copy of the string, without leading and trailing whitespace |
|---|