Java String replace() Method | java replace
❮StringMethods[1]ExampleReturnanewstringwhereall"l"charactersarereplacedwith"p"characters:StringmyStr="Hello";System.out.println(myStr.replace(l,p));TryitYourself»[2]DefinitionandUsageThereplace()methodsearchesastringforaspecifiedcharacter,andreturnsanewstringwherethespecifiedcharacter(s)arereplaced.SyntaxpublicStringreplace(charsearchChar,charnewChar)ParameterValuesParameterDescriptionsearchCharAchar,representingthecharacterthatwillbereplacedbythenewcharacternewCharAchar,representingthechar...
❮ String Methods[1]
ExampleReturn a new string where all "l" characters are replaced with "p" characters:
String myStr = "Hello"; System.out.println(myStr.replace(l, p));Try it Yourself »[2]
Definition and UsageThe 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 Parameter Description searchChar A char, representing the character that will be replaced by the new character newChar A 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) ❮ String Methods[3]
W3schools Pathfinder
Track your progress - its free!
...