0 votes
1 view
in Java by (5.8k points)
What's the difference between java.lang.String 's replace() and replaceAll() methods, other than later uses regex? For simple substitutions like, replace . with / , is there any difference?

1 Answer

0 votes
by (34.9k points)

In java.lang.String, the repair method each takes a pair of char's or a pair of CharSequence's (of which String is a subclass, so it'll gladly take a pair of String's). The repair program will replace all occurrences of a char or CharSequence. On the other hand, both String thoughts to replaceFirst and replaceAll are regular characters (regex). Using the reverse function can lead to subtle bugs.