I think using `replaceAll("\\s", "")` is incorrect here: 
```
System.out.println("a b".replaceAll("\\s", "").length()); // 2
System.out.println("a b".replaceAll("^\\s", "").replaceAll("\\s$", "").length()); // 3
```