Java replace() 方法
replace() 方法通過用 newChar 字符替換字符串中出現(xiàn)的所有 oldChar 字符,并返回替換后的新字符串。
語法
public String replace(char oldChar, char newChar)
參數(shù)
oldChar -- 原字符。
newChar -- 新字符。
返回值
替換后生成的新字符串。
實(shí)例
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')); } }
以上程序執(zhí)行結(jié)果為:
返回值 :hellT 返回值 :heDDo
更多建議: