Replace Characters in a String


public class Main {
    
    /**
     * This method replaces characters in a string
     */
    public void replaceCharacters() {
        

        String str = "aaa bbb ccc";
        
        str = str.replace('b', 'd');
        
        System.out.println(str);
    }
    
    /**
     * Starts the program
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main().replaceCharacters();
    }
}



 

When the code above is executed it will display:


aaa ddd ccc

0 comments:

                                                                

Site Meter