Math, asked by Such7326, 1 year ago

Differentiate between replace and replace all

Answers

Answered by komalAgrawal
2

Step-by-step explanation:

The replace method of the String class accepts two characters and it replaces all the occurrences of oldChar in this string with newChar.

The replaceAll() method replaces each substring of this string that matches the given regular expression with the given replacement.

The replace method will replace all occurrences of a char or CharSequence. On the other hand, both String arguments to replaceFirst

replaceAll are regular expressions (regex). Using the wrong function can lead to subtle bugs.

Similar questions