Not able to remove whitespace(s) in a string in java

Remove multiple white spaces in a string


String myString1 ="aye  bye  tye";
String myString2 =myString1.replaceAll("s+","");
System.out.println("replaced string ="+myString2);

In the output,

replaced string =aye  bye  tye

is getting printed

But if there is only one white space between the words like,

String myString1 ="aye bye tye";

the result is correctly coming as below:

replaced string =ayebyetye

I wonder where I am going wrong?

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.