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

int[] find(String[] criteria) -- help please

 
Derick Potgieter
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I`m struggling with the find method, i have my for loop ready to search thro the database and compare each criteria field. But how do i actually
compare a field if say criteria[i] = For example, "Fred" to return "Fred" or "Freddy".

How do you match the first 4 letters then to all the search criteria??

Thanks
Derick
 
Jon Entwistle
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Derick,

Originally posted by Derickll Potgieterll:
how do i actually
compare a field if say criteria[i] = For example, "Fred" to return "Fred" or "Freddy".

How do you match the first 4 letters then to all the search criteria??


Have a look at the startsWith(String str) method in String.

Cheers,

Jon
 
Derick Potgieter
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, sort of stupid of me...

i`m getting the criteria searching part right now, but i still need to make a list and then get a final list, please can you check this code and let me know if there is a better solution or how i can make a single list??


but how can i track my record numbers, i can match the data.
in the 2 lists and then make a final list, but i`m not
tracking my records numbers??
 
Jon Entwistle
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Derick,

The return from this method is just an array of record numbers - to do this you need to iterate over all of your records, incrementing a counter variable on each iteration. If the record matches (and the record has not been deleted), simply add an Integer object for the value of the counter to a Collection. When finished, declare a new int[] to the size of this Collection, populate it by converting the Integer values in your collection then return this array.

I have to be honest, I had trouble following your code. I would certainly avoid non-idiom constructs such as incrementing a different variable to your control variable within the for loop:



these make the code very dificult to follow.

Hope this helps

Cheers,

Jon
[ May 31, 2004: Message edited by: Jon Entwistle ]
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Derickll,
I reckon your code wouldn't work for all the cases.
If the criteria array contains 2 fields and if they both match, then it is added twice in the arraylist. Also if it contains only 1 field and the others are null, then it is added multiple times into the arraylist. Isn't it?
I guess variable "x" in your inner for loop could be your record number.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic