Write a method that replaces all occurrences of one string with another.
The predefined Java function replace may not be used for this --
you have to write it yourself.
| Call | Returns | Comments |
|---|---|---|
replace("yesterday", "yes", "no") | noterday | One occurrence replaced. |
replace("yesterday", "e", "") | ystrday | Many occurrences replaced. |
replace("yesterday", "xx", "!") | yesterday | No match, return unchanged. |
replace("yesterday", "", "!") | yesterday | Special case. Better not try to replace "" with anything, otherwise there will be an infinite loop. |
replace("xxxxxx", "xx", "x") | xxx | Start matching after previous replacement. |
replace("xxxxxx", "xx", "x") | xxx | Start matching after previous replacement. |
replace("xxxxxx", "xx", "xx") | xxx | Start matching after previous replacement to avoid infinite loop. |
replace("xxxxxx", "x", "xx") | xxx | Start matching after previous replacement to avoid memory overflow. |
static? What type
does it return?