• 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

findByCriteria returns long[]

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am doing B&S assignment and trying to implement findByCriteria here to search records in data file. My question is how do I know before have what the length of long[] is going to be?
I have couple of options to do this:
1) Loop through the data file, find matching records and store them in collection and at the end of method convert collection to array and return an array. I looked at arraylist and it stores only Object and has toArray method which converts it to Object[], in that case how do I implement this?
2) Loop through the database, store it in an array of boolean (where array length will be num of records in DB), if matching record found store true in array else false, keep count of number of trues encountered. Set long[] to that length and loop through boolean array to find which ones are true. This probably isnt the good way is it?

Any help on this is appreciated, I tried searching this forum but could not find much discussion on this.

Thanks in advance.
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would opt for choice number one. Store the values in an ArrayList, and use the toArray() method. Then loop through the Object array and fill up a long array.
 
Jay Ashar
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Paul.
reply
    Bookmark Topic Watch Topic
  • New Topic