Java - Strings Class-String replaceFirst() Method - Java

Description

This method replaces the first substring of this string that matches the given regular expression with the given replacement.

Syntax

Here is the syntax of this method −

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

This will produce the following result −

Output

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java Topics