If there are any additional spaces in a String. trim() is used to delete those extra spaces.
public class Test{
public static void main(String[] arg){
String firstString = " Hello ";
System.out.println("The trimmed String is : "+firstString.trim());
}
}
The trim() method removed all the additional spaces from the String "Hello".