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

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

+3
source share
2 answers
str.replaceAll("\\s+", "");

\ s Simple character: [\ t \ n \ x0B \ f \ r]

java.util.regex.Pattern contains all predefined classes.

+18
source

Use String.replaceAll with regex to remove all spaces:

s = s.replaceAll("\\s+", "");
+6
source

Source: https://habr.com/ru/post/1737306/


All Articles