File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

findByCriteria returns long[]

 
Jay Ashar
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Paul.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic