• Post Reply Bookmark Topic Watch Topic
  • New Topic

search array  RSS feed

 
matthew reid
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, im trying to make a method to search an arrayList and then if the object is found put a copy of that into another array so i can display all the matches.

this is what i have got. everything compilers and i dont get any runtime errors but ti does nothing and i cant find any decent guides to help solve my problem.

 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you verified that your tests are returning true? It is quite possible that your searches are simply failing to match what you are looking for, in which case you will get an empty List returned.
Why are you clearing a List? Why does that method seem to be doing so many things? A method shou‍ld do one thing. Create a method to search your List and return a new List<Sale> matching your search criteria and to do nothing else. Please note what I asked yesterday about whether a List is the best data structure. If you are repeatedly making linear searches, you might be better off with different data structures. Have a look in the Java™ Tutorials to see what sort of data structures are available.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!