aspose file tools*
The moose likes Java in General and the fly likes Filtering List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Filtering List" Watch "Filtering List" New topic
Author

Filtering List

Vladas Razas
Ranch Hand

Joined: Dec 02, 2003
Posts: 385
Hello fellow developers,

I need to filter a List (java.util.list). I.e. there is a list of people, and each person has a type assigned. How could we filter it, so recipient method would still be able to add/remove from the list, but all iterators and get()'s would act just as if there are only people with type X in it.

Thank you!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I think that you'll have to make a new sublist. I can't imagine of another method.


[My Blog]
All roads lead to JavaRanch
Vladas Razas
Ranch Hand

Joined: Dec 02, 2003
Posts: 385
That's a bit problematic, because the code I give list to, also updates it. And I need those updates synchronized with original list. Here is my code:


I have run into some problems with this approach: sometimes I start getting ConcurrentModificationException. When removing records I have to use iterator's remove. Maybe there is an easy way, I missed somehow?

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filtering List