String methods – trim() and length()

I this post, we will discuss about the string methods – trim() and length().

Let’s understand them one by one with examples.


The method trim() is used to remove leading and trailing white spaces from the input String.

e.g. Suppose, If we have a string ”   Name  “.  After using trim , String will remove the whitespaces i.e.  “Name”.

Output: After trimming the string – How are you???


It is used to find out the no. of character in the string ,that is nothing but the length of the string.

Output: The length of the string is – 11
Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.
String method- indexof
String methods - substring
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

1 Response

  1. August 6, 2015

    […] int length() […]

Leave a Reply

Your email address will not be published. Required fields are marked *