1

I have a situation as described below.

I do have Java Bean named Document and it has various properties. One property is

String documentStatus

and I do have List<Document> documentList. Then I do have List<String> statusList.

Now, I want a list of all those documents whose documentStatus are matching with given statusList.

One solution is to iterate documentList and match value using statusList.contains(document.getStatus()).

Secondly, Predicates in Java

Apart from this can anyone have any ideas ?

Any Help would be really appreciated.

Community
  • 1
  • 1
Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
  • 1
    You already have two possibilities which both provide a perfectly good solution. Why are you looking for other alternatives? Knowing this, would help in providing the answer you're looking for. – Pieter Dec 06 '11 at 10:28
  • As you show in your link, I would use the Predicates of the Google Guava library. – Dimitri Dec 06 '11 at 10:32
  • Indeed, the best, clearest approach is using the Guava library and do a Lists.filter(l, predicate); – Hiery Nomus Dec 06 '11 at 11:12
  • 1
    Think of copying your `statusList` into a set. Sets may provide O(1) implementations of `contains`, which might be significant when using `contains` in a loop. – Matthias Meid Dec 06 '11 at 11:13

1 Answers1

0

you can use contains method in list. Something like

for(Document doc:documentList){
if(statusList.contains(doc.getDocumentStatus()))
newDocList.add(doc)
}
dku.rajkumar
  • 18,414
  • 7
  • 41
  • 58