Java String replaceAll() method

Java String replaceAll() method returns a String replacing all the sequence of characters matching regular expression i.e regex and replacement string.

Syntax:

Parameters:

regex  :  regular expression

replacement  : replacement sequence of characters

Returns:

a new String i.e. replaced String

Java String replaceAll() example 1: replace character

Output:

Java String replaceAll() example 2: replace word

Output:

 Java String replaceAll() example 3

Output:

Java String replaceAll() example 4: remove white spaces

Output:

Leave a Comment