The java lang.string.trim()is a built-in function that eliminates leading and trailing spaces. The Unicode value of space character is ‘\u0020’. The trim() method in java checks this Unicode value before and after the string, if it exists then removes the spaces and returns the omitted string.
public String trim() The method accepts no parameters.
It returns the omitted string with no leading and trailing spaces.
Example: To show the working of string trim() function.
geeks for geeks has all java functions to read Chetna loves reading books
- Trim (Remove leading and trailing spaces) a string in Java
- Collator equals(String, String) method in Java with Example
- Collator compare(String, String) method in Java with Example
- Java.lang.string.replace() method in Java
- Java String contains() method with example
- Java String isEmpty() method with example
- Java String charAt() method with example
- ZoneOffset of(String) method in Java with Examples
- RuleBasedCollator getCollationElementIterator(String) method in Java
- String toString() Method in java with Examples
- Split() String method in Java with examples
- Java.lang.String.lastIndexOf() Method
- Java String subSequence() method with Examples
- CollationElementIterator setText(String) method in Java with Example
- PrintWriter write(String) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.