Now the problem rises when you do not want to write much code specifically to each clause, maybe you just are printing the stack trace or logging the exception. With the Java SE 7, you can write less code and be more flexible, something like this:

This approach is not optimized. First, it will produce additional lines of unnecessary code and therefore makes the code look ugly. Second, looping through element of an array is costly, especially when the array has two many elements.
A more optimized way of handling this case is with use of Regular Expressions. Without further a due, let us look at the code:

In this approach, we create a new regular expression by joining elements of array into an string and match it against the element with test() method. Just to remark, \b matches the empty string at the beginning or end of a word.