public static void main(String[] args) {
String comment = "垃圾,你真傻,滚开,去死吧!";
String[] bannedWords = {"垃圾", "滚", "去死", "傻"};
for (String word : bannedWords) {
comment = comment.replace(word, "*".repeat(word.length()));
}
System.out.println(comment);
}
输出如下:
**,你真*,*开,**吧!