Java-Replacement (Another Example)

replaceAll

The capability of replaceAll() makes the complex search of substrings possible within a string object. After a search, each matched substring is replaced with the given replacement.

Program

1

Program Source

public class Javaapp {
    
    public static void main(String[] args){
        
        String str1 = new String("Java Pro Tutorials");
        str1 = str1.replaceAll("Pro", "Programming");
        
        String str2 = new String("Java Pro Tutorials");
        str2 = str2.replaceAll("Pro(.*)", "Programming");
        
        String str3 = new String("Java Pro Tutorials");
        str3 = str3.replaceAll("(.*)Pro", "Programming");
        
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
   }
}

Leave a Comment