Replace One Character With The Other | Java Programs

Output:

*** Replace Character With Other ***

Original String: aleeee

Replacing 'e' with 'y'
New String:      alyyyy

Click Here For Java Online Compiler

Solution:

class ReplaceChar {

    public static void main(String[] args) {
        System.out.println("*** Replace Character With Other ***" + "\n");
        String string = "aleeee";
        // Replace all the 'e' characters with 'y' characters.
        String newString = string.replace('e', 'y');

        // Display the strings for comparison.
        System.out.println("Original String: " + string + "\n");
        System.out.println("Replacing 'e' with 'y'");
        System.out.println("New String:      " + newString);
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon