14 May String replace(char oldChar, char newChar) method on Java
The replace(char oldChar, char newChar) method in Java returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Syntax
Let us see the syntax,
String replace(char oldChar, char newChar)
Parameters
Let us see the parameters,
- oldChar − old character
- newChar − new character
Example
The following is an example of replace(char oldChar, char newChar),
public class StudyopediaDemo {
public static void main(String args[]) {
String message = new String("Studyopedia provides free learning content!");
System.out.println("String: "+message);
System.out.print("Result after replacing: " );
System.out.println(message.replace('e', 'E'));
}
}
Output
The following is the output,

No Comments