java关于替换字符串传参问题

        当使用方法里面的String参数的时候,在方法当中用replace操作字符串是不能操作的,因为String是引用类型,replace可以直接操作字符串可以参考replace方法源码,我是用javabean传的,表示有用!

public class SanShu {
    private String string;
    private String yl;
    private String th;

    public SanShu(){

    }

    public SanShu(String yl, String th,String string) {
        this.yl = yl;
        this.th = th;
        this.string = string;
    }

    public String getYl() {
        return yl;
    }

    public void setYl(String yl) {
        this.yl = yl;
    }

    public String getTh() {
        return th;
    }

    public void setTh(String th) {
        this.th = th;
    }

    public String getString() {
        return string;
    }

    public void setString(String string) {
        this.string = string;
    }

}

这是一个简单的javabean

public class TestMethed {
    public String replaceSt(SanShu sanShu){
        System.out.println(sanShu.getString());
        String replace = sanShu.getString().replaceAll(sanShu.getYl(),sanShu.getTh());
        System.out.println(replace);
        return replace;
    }
}

这是方法类。

public class YanMing {
    public static void main(String [] args){
        //String string = "654321";
        TestMethed testMethed = new TestMethed();
       // testMethed.run(string);
        String s = testMethed.replaceSt(new SanShu("54","3","654321"));
        System.out.println(s);
    }
}

这是主方法。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章