How to replaces all occurrences of given character with new character and returns new String in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
    
    public static void main(String[] args) {
  
        String s = "Java C C++ C# PHP VB Assembly";

        s = s.replace('P','W');
        System.out.println(s);
    }
}
   
/*
   
run:
   
Java C C++ C# WHW VB Assembly
   
*/

 



answered Oct 25, 2016 by avibootz
...