Jesper,
Thanks for your comments.
For the most part, you are correct.
If I were in Ranadhir's situation, I would first look for a commons collection solution because they often have exactly what I'm looking for, maybe something akin to Satou's solution.
If not, I would probably just iterate through the ArrayList, or secondarily implement your suggestion which was to write a utility class or method to save from writing the loop several times.
It would be ridiculous to use this kind of custom string-like object throughout an application, and I concede that in a software system you're likely to receive an ArrayList of Strings intact and would not want to convert all Strings to this type of object.
And for that, I'm sorry, I should have elaborated my intentions regarding this solution before posting it.
So what I should have said is
, if you really do not want to manually iterate over an ArrayList and want to make use of a regex in the contains method, and you have no concern for anything else and are programming in your own little ivory tower, you can do something like below...
Obviously, ostentatious concerns about elegance, the founding fathers desires for use of the equals() method, and String
optimalisations do not come in to play here.