String replaceAll (String regeX, String replace): This method replaces all substrings in the invoking string that matches the given regular expression pattern regeX with the specified replacement string replace. For example,
Str1.replaceAll(“[aeiou]”,”#”);
It will replace all vowels in the invoking string with # symbol. Here [aeiou] is a regular expression which means any of the characters between the square brackets will match
Str3.replaceAll(“is”,”was”);
This statement will replace the substring is with the substring was in the given string. You can get the details of the regular expression from the Sun’s website.
public class StringReplaceAll
{
public static void main(String[] args)
{
String strl = "Welcome";
String str3 = "Where there is a Will , there is a way";
System.out.println("str3.replaceAll(\"is\",\"was\") = " +str3.replaceAll("is" ,"was"));
System.out.println("strl.replaceAll(\"[aeiou]\" ,\"#\") = " +strl.replaceAll("[aeiou] " ,"#"));
}
}