Often beginners use string.replaceAll(" ", "") and even string.replaceAll("\\s", "") doesn't work properly, as Java's implementation of regex doesn't cover all the whitespaces (as per this stackoverflow)
So a method that relies on Character.isWhiteSpace is an improvement, can be used as method reference and also performs better.
So when the article uses "We can easily get rid of all the whitespace from each String" in its despription of strip, it's just wrong. strip only removes leading and trailing whitespace.
16
u/_INTER_ Sep 19 '18 edited Sep 19 '18
Often beginners use
string.replaceAll(" ", "")and evenstring.replaceAll("\\s", "")doesn't work properly, as Java's implementation of regex doesn't cover all the whitespaces (as per this stackoverflow)So a method that relies on Character.isWhiteSpace is an improvement, can be used as method reference and also performs better.