The String.trim() method returns a string whose value is this string, with any leading and trailing whitespace removed.
Java String.trim() Method Example
This is a complete example to demonstrate the usage of trim() method.
public class TrimExample {
public static void main(String[] args) {
String str = "javaguides ";
String subStr = str.trim();
System.out.println("trim the space from given string : " + subStr);
}
}
Output:
trim the space from given string: javaguides
Reference
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course