Here is a late answer, just for fun.
In such cases, I would suggest increasing speed readability. Of course, you can be super readable, but too slow, as in this super-compressed version:
private static String processWord(String x) { return x.replaceAll("[][(){},.;!?<>%]", ""); }
This is slow because every time you call this method, regex will be compiled. Therefore, you can precompile the regular expression.
private static final Pattern UNDESIRABLES = Pattern.compile("[][(){},.;!?<>%]"); private static String processWord(String x) { return UNDESIRABLES.matcher(x).replaceAll(""); }
This should be fast enough for most purposes, assuming the JVM regex engine optimizes character class searches. This is a solution that I would use personally.
Now, without profiling, I donβt know if you can do better by creating a table of your own characters (actually a code one):
private static final boolean[] CHARS_TO_KEEP = new boolean[];
Fill it out once, and then iterate, creating your final row. I will leave the code for you. :)
Again, I would not dive into such an optimization. The code has become too difficult to read. Is performance such a problem? Also remember that modern languages ββare JITted, and after warming up they will work better, so use a good profiler.
One thing that should be mentioned is that the example in the original question is very inactive because you are creating a whole bunch of temporary lines! If the compiler does not optimize all of this, this particular solution will be the worst.