Java文字列replace()メソッド
例
すべての「l」文字が「p」文字に置き換えられた新しい文字列を返します。
String myStr = "Hello";
System.out.println(myStr.replace('l', 'p'));
定義と使用法
このreplace()
メソッドは、文字列で指定された文字を検索し、指定された文字が置き換えられた新しい文字列を返します。
構文
public String replace(char searchChar, char newChar)
パラメータ値
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 |
技術的な詳細
戻り値: | 新しいString 、指定された文字が新しい文字に置き換えられた場合 |
---|
❮文字列メソッド