September 2019
Intermediate to advanced
816 pages
18h 47m
English
The solution to this problem consists of using the String.replaceAll() method with the \s regular expression. Mainly, \s removes all white spaces, including the non-visible ones, such as \t, \n, and \r:
public static String removeWhitespaces(String str) { return str.replaceAll("\\s", "");}