Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

filter java.util.List based some requirements.  RSS feed

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while I am doing a java.util.List, I always need to filter the List based some requirements.

For example , I have a People object which has "name" and "age" attributes. Now, question is , how to get all Peoples, in the a List, whose ages equals to "30" ?

if we have a customized List.indexOf(obj, comparator), it will be better. or we have some open source java List API to solve this problem ?

Thanks.
 
Sheriff
Posts: 12319
200
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know if it helps you but I found these:

http://www.javapractices.com/Topic163.cjp
http://www.publicobject.com/glazedlists/
 
Junilu Lacar
Sheriff
Posts: 12319
200
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jakarta Commons Collection also has the following classes you might want to look at:

org.apache.commons.collections.iterators.FilterIterator
org.apache.commons.collections.iterators.FilterListIterator

See http://jakarta.apache.org/commons/collections/apidocs/index.html
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

But I can't find an example how to use Apache Collections FilterIterator . Apache web site can't find it, either.

Thanks.
 
Junilu Lacar
Sheriff
Posts: 12319
200
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a small unit test to illustrate the use:

 
Junilu Lacar
Sheriff
Posts: 12319
200
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be easy enough for you to replace the anonymous Predicate class with something like an AgePredicate:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!