How to replace all characters in a Java string with stars

前端 未结 9 1936
不思量自难忘°
不思量自难忘° 2020-12-01 07:32

I want to replace all the characters in a Java String with * character. So it shouldn\'t matter what character it is, it should be replaced with a *

9条回答
  •  北海茫月
    2020-12-01 08:03

    public String allStar(String s) {
        StringBuilder sb = new StringBuilder(s.length());
        for (int i = 0; i < s.length(); i++) {
            sb.append('*');
        }
        return sb.toString();
    }
    

提交回复
热议问题