remove spaces from beginning and end of string java code example
Example 1: remove spaces at beginning and end of string java
String withSpaces = " Hi ";
String withoutSpaces = withSpaces.trim();
Example 2: java remove space at the end of string
String str = "Hello ";
System.out.println(str.trim()); // "Hello"