Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java String replace() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ myStr = "Hello";3Order
Put the learning moves in the order that makes the concept easiest to apply.
The replace() method searches a string for a specified character, and returns a new string where the specified character(s) are replaced.
Definition and Usage
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
| 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) |
|---|