replace() - String Methods in Java
This article is a part of
String Methods in Java.
The replace() method searches the string for a specified character and then
returns a
string where the specified character is replaced. There are two parameters in this method,
namely oldChar and newChar. The oldChar represents the character
to be replaced, whereas the
newChar represents the character with which it should be replaced.
Return type
The return type for replace() method is String. Let us look at an example for this method.
Output
Let us look at the output of the above.
replaceFirst()
replaceFirst() method replaces only the first occurrence of the oldChar with newChar. Let us look at the example.
Output
Let us look at the output of the above.