Java String replace() method

Java String replace() method returns new String by replacing old characters with new characters or old CharSequence to new CharSequence.

Syntax:

Parameters:

oldChar : old Character

newChar : new Character

target : target sequence of characters

replacement: replacement sequence of characters

Returns:

a new String i.e. replaced Strin

Java String replace(char old, char new) method example 1

Output:

Java String replace(CharSequence target, CharSequence replacement) method example 2

Output:

Java String replace method Example 3

Output:

Java String replace method Example 4

Output:

Leave a Comment