The String.replaceAll(String regex, String replacement) method replaces each substring of this string that matches the given regular expression with the given replacement.
Java String.replaceAll() Method Example
This is a complete example to demonstrate the usage of replaceAll() methods.
public class ReplaceAllExample {
public static void main(String[] args) {
String str = "javaguides";
String subStr = str.replaceAll("[a-z]", "java");
System.out.println(subStr);
}
}
Output:
javajavajavajavajavajavajavajavajavajava
Comments
Post a Comment