java.lang.string.replace()

the replace() method of Java String Class.

java.lang.string.replace()

The example discuss about the replace() method of Java String Class in Java.

Use of string.replace() method in Java
For a example if you wants to replace certain characters from the given string with your ones...then you should use the replace() method. Basically, replace method in Java replace the given char from the new one.

Syntax:
public String replace(char oldChar, char newChar)

See the example below...

public class Replacing
{
public static void main(String[] args)
{
String str = "Is Java Programming.";

//will replace all the 's' characters with 'n' character.
String toStr = str.replace('s', 'n');

// Display the strings for comparison.
System.out.println("Orignal String = " + str);
System.out.println("New String = " + toStr);
}
}

the Output is:
Orignal String = Is Java Programming.
New String = In Java Programming.