Java Program to replace a Character



Java Program to replace a Character

Sample Code

public class replace_character {

  public static void main(String[] args) {
    String str = "The quick brown fox jumps over the lazy dog.";

    // Replace all the 'd' characters with 'f' characters.
    String new_str = str.replace('d', 'f');

    // Display the strings for comparison.
    System.out.println("Original string: " + str);
    System.out.println("New String: " + new_str);
  }
}

Output

Original string: The quick brown fox jumps over the lazy dog.                                                 
New String: The quick brown fox jumps over the lazy fog.

Related Searches to Java Program to replace a Character