【发布时间】:2011-05-06 17:55:55
【问题描述】:
List<String> cursewords = new ArrayList<String>();
cursewords.add("darn it");
cursewords.add("gosh");
cursewords.add("gee whiz");
cursewords.add("golly");
String text = " Golly ";
if (cursewords.contains(text.trim().toLowerCase()) {
System.out.println("found curse:" + text);
}
有没有更好的方法来做到这一点?
我的过滤器没有捕捉到它需要的东西。
【问题讨论】:
-
您发布的代码有效吗?在我看来没问题。我对“未捕获”位感到困惑。
-
在这种情况下 text.trim().toLowerCase() 返回什么?
-
@duffymo:我认为 Donut 下面的评论解决了这个问题。我需要一些方法来检查
text中是否存在cursewords条目anywhere。 -
作为记录,您可能需要查看 Jeff 的这篇关于过滤器的文章 codinghorror.com/blog/2008/10/…
-
感谢你用你那可怕的脏话列表度过我的一天 :-)