WEB DEVELOPER SITE
PHP7
 

Java String replaceFirst() Method



This method Returns the character at the specified index


Syntax

Here is the syntax of this method −

public String replaceFirst(String regex, String replacement)

Parameters

Here is the detail of parameters −

  • regex − the regular expression to which this string is to be matched.

  • replacement − the string which would replace found expression.

Return Value

  • This method returns a resulting String.

Example


import java.io.*;
public class Myproject {

   public static void main(String args[]) {
      String Str = new String("Welcome to Welookups.com");

      System.out.print("Return Value :" );
      System.out.println(Str.replaceFirst("(.*)wE(.*)", "AMROOD"));

      System.out.print("Return Value :" );
      System.out.println(Str.replaceFirst("WE", "AMROOD"));
   }
}

Run example »