• Post Reply Bookmark Topic Watch Topic
  • New Topic

Searching an ArrayList  RSS feed

 
Shey Gordon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code fragment I have for searching my ArrayList. Now, each contact is stored in the ArrayList with five elements (first name, last name, etc.) and they're Strings. The error I get when I try to compile my program lies within this code fragment. It says it cannot find the symbol for the search method. I'm a bit stumped by this as it's been some time since I took my first programming class and now I'm not quite sure what to do with this error.

 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shey, Please be more clear. What is SAAddressBook and search ?

i suppose SAAddressBook is the array list name and you are trying to use search method for searching aBook. If that so then there is no such factory search method in arrayList. You need to use contains methods in it which return boolean value.

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tushar Goel wrote:You need to use contains methods in it which return boolean value.

@Shey: Or indeed indexOf()/lastIndexOf(), which will return an index for you (or -1).

My advice: read up the API docs for List (java.util.List) and ArrayList (you can click on either underlined link to get them).

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