Java Stringtrim() Method
Example
Remove whitespace from both sides of a string:
String myStr = " Hello World! ";System.out.println(myStr);System.out.println(myStr.trim());Definition and Usage
Thetrim() 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: | AString value, which is a copy of the string, without leading and trailing whitespace |
|---|
❮ String Methods

