Replaces all occurrences of a captured group by the result of closure on that text.
Syntax
void replaceAll(String regex, String replacement)
Parameters
- regex โ the regular expression to which this string is to be matched.
- replacement โ the string which would replace found expression.
Return Value
This method returns the resulting String.
Example
Following is an example of the usage of this method โ
class Example { static void main(String[] args) { String a = "Hello World Hello"; println(a.replaceAll("Hello","Bye")); println(a.replaceAll("World","Hello")); } }
When we run the above program, we will get the following result โ
Bye World Bye Hello Hello Hello
Previous Page:-Click Here