by Dinesh Thakur Category: array

String replaceFirst (String regex, String replace): This method replaces the first substring in the invoking string that matches the given regular expression with the specified replacement string replace. For example,


It will replace the first occurrence of substring is with the substring was in the given string.

public class StringReplaceFirst

     public static void main(String[] args)
            String str3 = "Where there is a Will , there is a way";
            System.out.println("str3.replaceFirst(\"is\" ,\"was\") = " +str3.replaceFirst("is" ,"was"));

String replaceFirst() in Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles