String Handling – trim ( )

trim ( )

Syntax

     String trim ( );

 

trim() method of String class is used to remove the prefix and postfix spaces of invoking string and returns the resultant string.

 

class Example 1

{

public static void main (String arg[ ])

{

String s1 = “ Code project ”;

System.out.println(s1);

String s2 = s1.trim();

System.out.println(s2);

}

}

output

Code project

Code project

Leave a Reply

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