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,
1 2 3 |
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),
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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