以下是一个简单的Java
敏感词过滤
工具类:
```
im
port java.util.HashSet;
im
port java.util.Set;
public class SensitiveWordFilter {
private Set<String> sensitiveWords = new HashSet<>();
public SensitiveWordFilter() {
// 初始化
敏感词列表
sensitiveWords.add("
敏感词1");
sensitiveWords.add("
敏感词2");
sensitiveWords.add("
敏感词3");
// ...
}
public String filter(String text) {
for (String word : sensitiveWords) {
if (text.co
ntains(word)) {
text = text.replaceAll(word, "***");
}
}
return text;
}
}
```
使用方法:
```
SensitiveWordFilter filter = new SensitiveWordFilter();
String text = "这是一段包含
敏感词的文本,
敏感词1,
敏感词2,
敏感词3";
String filteredText = filter.filter(text);
System.out.println(filteredText);
```
输出结果:
```
这是一段包含***的文本,***,***,***
本文地址:http://nhjcxspj.xhstdz.com/quote/1535.html
物流园资讯网 http://nhjcxspj.xhstdz.com/ , 查看更多