此方法返回一个新字符串,该字符串是用newChar替换oldChar的字符。
public String replace(char oldChar, char newChar)
这是参数的详细信息-
oldChar - 旧字符。
newChar - 新字符。
通过将每次出现的oldChar替换为newChar,返回从该字符串派生的字符串。
import java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Welcome to Learnfk.com"); System.out.print("返回值 :" ); System.out.println(Str.replace('o', 'T')); System.out.print("返回值 :" ); System.out.println(Str.replace('f', 'D')); }
这将产生以下输出-
返回值 :WelcTme tT Learnfk.cTm 返回值 :Welcome to LearnDk.com
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Python实战 · 从0到1搭建直播视频平台 -〔Barry〕