replace() replaceAll() replaceFirst()
With the help of replace() function in Java, you can replace characters in your string. Lets study each Java string API functions in details: Syntax: Parameters: oldCh − old character newCh − new character Return Value The Java replace() function returns a string by replacing oldCh with newCh. Example of replace() in Java: Let’s understand replace() in Java function with an example: Output: Original String is ‘: the quick fox jumped String after replacing ‘fox’ with ‘dog’: the quick dog jumped String after replacing all ‘t’ with ‘a’: ahe quick fox jumped Signature: Parameters: regx: regular expression replacement: replacement sequence of characters Example: Output: Guru99isasiteprovidingfreetutorials Syntax Parameters rgex − the regular expression to which given string need to matched. replacement − the string that replaces regular expression. Return Value This method returns resulting String as an output. Example of replaceFirst() in Java: Output: Thi9 website providing free tutorials