Pages

Wednesday, December 03, 2008

I find the below piece of code pretty useful for filtering purposes in java. I use the apache Commons collection library for this purpose. In the below code snippet, I am filtering on id in the model Data present in the List. After running this code snippet, the 'list' will contain only those Data Objects that satisfy the filter criteria, in this case that will be 'userId = Id'. Predicate defines the filter criteria in the snippet below.