Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get filtered values from list<String>

 
srikanth Thandra
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi guys,

I have a requirement of applying filter on list<String>. I am building a list<String> say cityNamesList, which contains values like below:

KOTHAPETA,PEDDAPALLE,KUPPAM,SIRCILLA,KAKINADA RURAL,PONNUR etc..
I am having a text box in the user interface side. When the user types a character in the text box, i capture that character and have to show the city names containing that character that user typed.

Ex: If user has typed K then from the above list i have to show the city names that contains letter 'K'

How to achieve this? Kindly give any ideas?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so far what you have done? please post the detail, so that we can help you.
 
Steven Bruton
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a document listener to the text field to capture the input and to filter the list you could create a method like so;



 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Google Guava collections libraries do this naturally. They have a "filter" function that iterates over a collection, which can be an List, ArrayList, Set, etc.
Free and open source.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic