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)
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:
3. Observe that the output is displayed in the console as shown below:
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)