Home >>Java String Methods >Java String replaceAll() method
Java replaceAll() method in java string is used to returns a string that replaces all the sequence of characters that match regex and replacement string.
public String replaceAll(String regex, String replacement) { return Pattern.compile(regex).matcher(this).replaceAll(replacement); }
public String replaceAll(String regex, String replacement)
regex - This parameter is used for regular expression
replacement - This parameter is used for replacement sequence of characters
Returns - It is used to return replaced string
public class ReplaceAllExample1
{
public static void main(String args[])
{
String n1="Education Website";
String replaceString=n1.replaceAll("e","A");
System.out.println(replaceString);
}
}
public class ReplaceAllExample2
{
public static void main(String args[])
{
String Name="Hello, how are you";
String replaceString=Name.replaceAll("are","was");
System.out.println(replaceString);
}
}