Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (13.1k points)

Can anyone help me understand the difference between these expressions:

x = x.replaceAll("\\s", "");

x = x.replaceAll("\\s+", "");

1 Answer

0 votes
by (26.7k points)

Basically, \\s helps us to match for the single whitespace character whereas, \\s+ helps us to match the sequence of more than one whitespace character. It would be more efficient if you use \\s+.

I hope this will help.

Want to know more about Java? Prefer this tutorial on Learn Java.

Want to become a Java Expert? Join Java Training now!!

Related questions

0 votes
1 answer
0 votes
1 answer
asked Nov 13, 2019 in Java by Nigam (4k points)
0 votes
1 answer
asked Nov 12, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer

Browse Categories

...