Home >>Java String Methods >Java String trim() Method
The trim() method in Java String is used to removes whitespace from both ends of a string.
public String trim()
None
It is used to return A String value, which is a copy of the string, without leading and trailing whitespace
public class MyClass
{
public static void main(String[] args)
{
String strln1 = " Hello Phptpoint! ";
System.out.println(strln1);
System.out.println(strln1.trim());
}
}
public class MyClass
{
public static void main(String[] args)
{
String n1 =" hello Phptpoint ";
System.out.println(n1.length());
System.out.println(n1);
String tr = n1.trim();
System.out.println(tr.length());
System.out.println(tr);
}
}