• Post Reply Bookmark Topic Watch Topic
  • New Topic

Searching through an array question  RSS feed

 
Aron Silvester
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple solution -- > loop through array , do string comparison (use startsWith() method of String class ... like aaray[i].startsWith("Chris")) , stores the matched strings in separate list .. shown the updated user name list on browser
Please note that this solution may not be best if we consider performances especially when array size is large.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my previous post talks about how to deal it in Java code.
Another good alternative is JQuery Autocomplete plugin http://jqueryui.com/autocomplete/
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Conrado, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/93131-searching-through-array-question.html
 
Aron Silvester
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"I posted this question the other day in http://www.java-forums.org/new-java/93128-how-print-stored-content-when-using-arraylist.html#post397583, but wasn't able to get a good answer, so now I'm asking here..."
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Conrado Sanchez wrote:"I posted this question the other day in http://www.java-forums.org/new-java/93128-how-print-stored-content-when-using-arraylist.html#post397583, but wasn't able to get a good answer, so now I'm asking here..."


That was the other cross posted topic, posted here about 3 hours after the other, and after Norm had responded 3 times (and just minutes before his fourth response).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!