String replace(char oldChar, char newChar) method on Java

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,

Parameters

Let us see the parameters,

  • oldChar −  old character
  • newChar − new character

Example

The following is an example of replace(char oldChar, char newChar),

Output

The following is the output,

Java string replace method

String regionMatches(int toffset, String other, int ooffset, int len) method in Java
String replaceAll(String regex, String replacement) method in Java
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create free tutorials for all.

No Comments

Post A Comment