The 's' replaces 1 space match at a time however the 's+' replaces The complete Room sequence at the same time with the 2nd parameter. On the other hand x.replaceAll("\s+", ""); is going to be a lot more efficient technique for trimming spaces (if string may have numerous contiguous Areas) https://mariogwlym.blogkoo.com/mantra-mushroom-chocolate-bars-can-be-fun-for-anyone-50977780