A
AAJ
Hi all
I have some objects that I add to an ArrayList. Each object is from the same
class and has methods etc. Each can be identified by a unique property, in
this case PK
e.g.
PK =1 for Instance1.PK
PK =2 for Instance2.PK
etc
I need to be able to locate the index of a specific PK within the Array List
using the .PK property. I know I could use a FOREACH loop, and check each PK
of the Current.PK until I find the correct one.
I'm hoping there is a built in way of doing this. I looked at
ArrayList.BinarySearch, but this seems to compare the full object, but its
the PK that I need to find, and then return the index of the located object.
I can find references to Icomparable, Icompare, I can find references to
finding integers, strings etc, but I cant find searching for a particular
property. I am also aware that for a binary search, the list needs to be
sorted.
can any one point me to a tutorial, perhaps I should be using a hashtable
and storing PK
andy advice would be welcome
thanks in advance
Andy
I have some objects that I add to an ArrayList. Each object is from the same
class and has methods etc. Each can be identified by a unique property, in
this case PK
e.g.
PK =1 for Instance1.PK
PK =2 for Instance2.PK
etc
I need to be able to locate the index of a specific PK within the Array List
using the .PK property. I know I could use a FOREACH loop, and check each PK
of the Current.PK until I find the correct one.
I'm hoping there is a built in way of doing this. I looked at
ArrayList.BinarySearch, but this seems to compare the full object, but its
the PK that I need to find, and then return the index of the located object.
I can find references to Icomparable, Icompare, I can find references to
finding integers, strings etc, but I cant find searching for a particular
property. I am also aware that for a binary search, the list needs to be
sorted.
can any one point me to a tutorial, perhaps I should be using a hashtable
and storing PK
andy advice would be welcome
thanks in advance
Andy