Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Filtering List  RSS feed

 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you'll have to make a new sublist. I can't imagine of another method.
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!