-3

Please anyone tell me what is the difference between:

  1. .replaceAll("\\s","");
  2. .replaceAll("\\s+","");
  3. and .replaceAll("\\s+$","");
  • 2
    You might also read trough http://www.regular-expressions.info/ and http://www.regular-expressions.info/refanchors.html specifically – papanito Jan 11 '21 at 15:22

1 Answers1

3

s.replaceAll("\\s", "") Replace each space character with nothing.

s.replaceAll("\\s+", "") Replace each group of 1 or more spaces with nothing.

s.replaceAll("\\s+$", "") Replace each group of 1 or more spaces at the end of the string with nothing.

All of these special characters are explained well in the javadoc.

NomadMaker
  • 447
  • 1
  • 5
  • 9