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