Java String.replaceFirst() Method Example

The String.replaceFirst(String regex, String replacement) method replaces the first substring of this string that matches the given regular expression with the given replacement.

Java String.replaceFirst() Method Example

This is a complete example to demonstrate the usage of replaceFirst()  methods.
public class ReplaceExample {
    public static void main(String[] args) {
        String str = "javaguides";
        String subStr = str.replaceFirst("[a-z]", "java");



Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course