The 's' replaces just one Room match at any given time nevertheless the 's+' replaces the whole Place sequence simultaneously with the 2nd parameter. On the other hand x.replaceAll("\s+", ""); might be a lot more effective technique for trimming spaces (if string might have several contiguous spaces) because of probably https://mantra-mushroom-chocolate21975.worldblogged.com/37321254/the-single-best-strategy-to-use-for-s