This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to search within a list? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to search within a list?" Watch "How to search within a list?" New topic
Author

How to search within a list?

Mike Croteau
Greenhorn

Joined: Apr 09, 2007
Posts: 8
I have created an address book which holds information including first name, last name, address, city, etc. I have text fields for each of those values in which I use to set. How can I use those text fields to type in part of an address to find an address that matches within my list collection? Thanks in advance.
Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70
i am assuming you have a seperate class for address which contains name, city, etc... and you are using arraylist or set from collections interface.
you can implement comparator and can make a search or if you are using arraylist then



in your case BankAccount will be replace by Address and then replace getAccountNumber() to your needs for searching.

Hope this helps


SCJP 1.5
Mike Croteau
Greenhorn

Joined: Apr 09, 2007
Posts: 8
Thanks for the post! This is helpful, however, have another element to throw into the pot. What if I needed to do a partial search... example:

Let say you have a list of animals:

Cat
Dog
Bat

And you search for animals containing "at" within the name. You need to return: Cat, and Bat. How can i do this? Thanks again!

Mike
 
Don't get me started about those stupid light bulbs.
 
subject: How to search within a list?
 
Similar Threads
Submit form text fields (group) with same name
Help for editable list box
how to map this using EJB3?
How to retain values...
Propagating an event to the cell renderer