Java如何替换字符串中的字符?
package org.nhooo.example.lang;
public class StringReplace {
public static void main(String[] args) {
String text = "The quick brown fox jumps over the lazy dog";
System.out.println("Before: " + text);
//替换方法替换所有出现的字符
//'o'与'u'并返回一个新的字符串对象。
text = text.replace('o', 'u');
System.out.println("After : " + text);
}
}代码段的结果:
Before: The quick brown fox jumps over the lazy dog After : The quick bruwn fux jumps uver the lazy dug
热门推荐
10 最美婆婆生日祝福语简短
11 姐姐生日祝福语漂亮简短
12 恭贺新婚文案祝福语简短
13 六一互换礼物祝福语简短
14 成长仪式的简短祝福语
15 婚礼明星的祝福语简短
16 中午生日家庭祝福语简短
17 玫瑰礼盒祝福语大全简短
18 简短霸气的考试祝福语