Javatpoint Logo
Javatpoint Logo

Java String trim()

The java string trim() method eliminates leading and trailing spaces. The unicode value of space character is '\u0020'. The trim() method in java string checks this unicode value before and after the string, if it exists then removes the spaces and returns the omitted string.

The string trim() method doesn't omits middle spaces.

Internal implementation


The signature or syntax of string trim method is given below:


string with omitted leading and trailing spaces

Java String trim() method example

Test it Now
  hello string   javatpoint
hello stringjavatpoint   

Java String trim() Method Example 2

This example demonstrate the use of trim method. This method removes all the trailing spaces so the length of string also reduces. Let's see an example.

  hello java string   
hello java string

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA