• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to search within a list?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mike Croteau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic