To add to the already selected "Best Answer" (and others that are just as good like Suragch's), String.replace()
is constrained by replacing characters that are sequential (thus taking CharSequence
). However, String.replaceAll()
is not constrained by replacing sequential characters only. You could replace non-sequential characters as well as long as your regular expression is constructed in such a way.
Also (most importantly and painfully obvious), replace()
can only replace literal values; whereas replaceAll
can replace 'like' sequences (not necessarily identical).