Java字符串替换

来源:互联网 发布:新电脑怎么连接网络 编辑:程序博客网 时间:2024/05/22 03:16
public class TestGroup {


public static void main(String[] args) {

// -----将字符串“我我....我...要.要...要要...要学....学学..学.编..编编.编.程.程.程..程"还原成我要学编程
String s="我我....我...要.要...要要...要学....学学..学.编..编编.编.程.程.程..程";
String s2=s.replaceAll("\\.", "");
System.out.println(s2);
String s3=s2.replaceAll("(.)\\1+", "$1");
System.out.println(s3);

}

}