bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String replace() Method

❮ String Methods

Example

String myStr = "Hello";
System.out.println(myStr.replace('l', 'p'));

Definition and Usage

The replace() method searches a string for a specified character, and returns a new string where the specified character(s) are replaced.

Syntax

public String replace(char
searchChar , char
newChar )

Parameter Values

ParameterDescription
searchCharA char , representing the character that will be replaced by the new character
newCharA char , representing the character to replace the searchChar with

Technical Details

Returns:A new String , where the specified character has been replaced by the new character(s)

Previous

Java String regionMatches() Method

Next

Java String replaceAll() Method