Profanity Filter Performance in Java
<p>I have a requirement to filter profanity out of users' submissions in a Java-based web application. The client is aware of both the <a href="http://en.wikipedia.org/wiki/Scunthorpe_problem" rel="nofollow">Scunthorpe Problem</a> and the <a href="http://forums.thedailywtf.com/forums/t/5552.aspx" rel="nofollow">Clbuttic Problem</a> and have accepted the consequences. Please, I don't desire a debate on the merits of lack thereof of censorship.</p>

<p>There are two bits of data:</p>

<ol>
<li>The user's submission, which can potentially contain 500 words or so;</li>
<li>A single-column database table containing words that are disallowed. There may be many thousands of records in this table.</li>
</ol>

<p>The present solution seems wrong to me:</p>

<ol>
<li>The entire table is loaded into a static String[] on startup into a Singleton (thus residing in memory).</li>
<li>For each user submission we loop through the array and do a .indexOf() to see if any given word in the String[] appears in the submission.</li>
<li>If it appears, we replace with %$#@%-style characters. This is done by tokenizing the user submission, looping through the entire user submission as tokens (again), and replacing each instance of the found word.</li>
</ol>

<p>There may be brilliance in this solution, but I'm skeptical. And having looked at it for a while I can't find my way past it.</p>

<p>Questions is, what is a solution that will give good performance and hopefully be reasonably sane for future developers to maintain after I get fired for failing to filter out some obscure word I've never heard of?</p>
