My scenario
Filter a Java Collection such a frequent scenario and I am seeking the best methodology to do so. After some searching in StackOverflow, I can only see recommendation of specific collection filtering method without statistical comparsions for speed. Somebody recommended Predicate Some recommended lambdaj
I would like to see if somebody studied that already. So, the question is: "What is the best way to filter a Java Collection, in terms of readability and speed?"
Scope
I would like to know the study result of some remarkable methodology in the web, they are: (In certain, if you have another (better) choice, feel free to edit my question)
- While looping
- CollectionUtils Predicate
- lambdaj
- CQEngine
Possible performance study details
We may assume there is a WS call which need 0.05seconds to execute. And we may call it for 100 times.
getSomething() // 0.05 seconds to execute
Then we may compare their performance in scenarios like
Single Result performance (assume there is only one result returned by certain criteria. When the object is found, quit the searching) 1.1. Best case scenario 1.2 Worst case scenario 1.3 Average case scenario
Multiple result performance (assume there is a collection returned, may more than one result)
Thanks for answering!