Google+

142. Using 'trim( )' method








trim( ) method removes the white space before and after the specified string.
trim( ) method wont remove the white space between the words in the specified string.

Example: 

 "         One  Two       ".trim( );  -> This method will remove the white space before and after the specified string and will output the resulting string as "One Two"  (Observe that the white space between the words is not removed by this method)

Lets implement this on Eclipse IDE:

1. Create 'trimDemo' class under any project as shown below:



2. Save and Run the 'trimDemo' class file
3. Observe that the output is displayed in the console as shown below:



Download this project:

Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)




Please comment below to feedback or ask questions.

Using 'toLowerCase( )' and 'toUpperCase( )' methods will be explained in the next post.




No comments: