The 's' replaces 1 Area match at a time even so the 's+' replaces the whole space sequence at the same time with the 2nd parameter.Nevertheless x.replaceAll("s+", ""); will likely be far more successful strategy for trimming spaces (if string can have numerous contiguous Areas) for the reason that of probably fewer no of replacements owing the to f