Java String Replace
# Java replace() Method
[Java String Class](#)
* * *
The replace() method replaces all occurrences of a character (searchChar) in a string with a new character (newChar) and returns the new string.
### Syntax
public String replace(char searchChar, char newChar)
### Parameters
* **searchChar** -- The original character.
* **newChar** -- The new character.
### Return Value
The new string generated after replacement.
### Example
The following example replaces characters in the string "Tutorial":
## Example
public class Main {
public static void main(String args[]){
String Str =new String("Tutorial");
System.out.print("Return Value :");
System.out.println(Str.replace('o', 'T'));
System.out.print("Return Value :");
System.out.println(Str.replace('u', 'D'));
}
}
The output of the above program is:
Return Value :RunTTbReturn Value :RDnoob
* * Java String Class](#)
YouTip