trim string java

trim() String Example

java.lang.String class comes with trim() String method to remove both leading and trailing whitespaces in the string. After trimming, a new string is returned. The signature of trim() String is given as defined in Java API. public String trim(): Returns a new string after deleting both prefix and suffix whitespaces…