Java 教程
replace() 方法通過用 newChar 字符替換字符串中出現(xiàn)的所有 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')); ????} }
以上程序執(zhí)行結(jié)果為:
返回值 :hellT 返回值 :heDDo