メソッドreplace()は、別のString内のStringのすべての出現またはcharのすべての出現を別のcharに置き換えます

 

利用可能な署名

public String replace(char oldChar, char newChar)
public String replace(CharSequence target, CharSequence replacement)

@Test
void whenReplaceOldCharNewChar_thenCorrect() {
    String s = "wslcoms to basldung";

    assertEquals("welcome to baeldung", s.replace('s', 'e'));
}
@Test
void whenReplaceTargetReplacement_thenCorrect() {
    String s = "welcome at baeldung, login at your course";

    assertEquals("welcome to baeldung, login to your course", s.replace("at", "to"));
}