Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k 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 (46k 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.

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...