()メソッドを置き換えるJAVA
replace()メソッドは、newCharに文字を持つすべてのoldChar文字列を置き換え、新しい置換文字列を返します。
文法
public String replace(char oldChar, char newChar)
パラメータ
oldChar -オリジナルキャラクター。
すべてnewChar -新しい文字。
戻り値
世代後の新しい文字列に置き換え。
例
public class Test { public static void main(String args[]) { String Str = new String("hello"); System.out.print("返回值 :" ); System.out.println(Str.replace('o', 'T')); System.out.print("返回值 :" ); System.out.println(Str.replace('l', 'D')); } }
上記プログラムの実行結果:
返回值 :hellT 返回值 :heDDo