Replace String Example in Java


/**
 * @author Mallikarjun G
 *
 */
public class JavaStringReplaceExample {
    /**
     * @param args
     */
    public static void main(String args[]) {      
        String str = “Replace String”;
        System.out.println(str.replace(‘R’, ‘A’));// Replaceing R with a in str
        System.out.println(str.replaceFirst(“Re”, “Ra”));// Replaceing First Re with Ra in str  
        System.out.println(str.replaceAll(“Re”, “Ra”)); // Replaceing All Re with Ra in str   

    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.