字符串替换

示例:

使用一个指定的新的字符串替换掉已有的字符串数据,字符串的替换可以使用的方法如下:

public class StringDemo {
    public static void main(String[] args) {
        String str = "helloworld";
        System.out.println(str.replaceAll("l","_"));     //替换所有的内容
        System.out.println(str.replaceFirst("l","_"));   //替换首个内容
    }
}

输出:

he__owor_d
he_loworld

 

posted @ 2018-07-09 17:00  悠然现南山  阅读(147)  评论(0编辑  收藏  举报