How to remove the \n, \t and spaces between the strings in java?

java, regex, string

Solution

str.replaceAll("\\s+", "");

\s A whitespace character: [ \t\n\x0B\f\r]

`java.util.regex.Pattern` has all the predefined classes.

Problem

How do you remove the \n, \t and spaces between strings in java?

Original source