I have a list of objects of class X. X has a unique identifier property P. Given a value p, I want to see if the list contains an object where x.P = p. Very simple, I ended up using a for loop to iterate over the objects in listX, breaking when I found the first occurrence.

Before doing that, however, I tried to find something in Commons that would do this for me. The closest I could find was org.apache.commons.collections.CollectionUtils.find(java.util.Collection collection, Predicate predicate). However, I couldn't find a simple PropertyPredicate that allowed me to say "look for objects whose property P is p". That seems like one of the most obvious uses of find, so I believe I'm just not looking in the right place.

I'd appreciate a pointer to where I can find this.  Thanks.

--
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to