Bhavesh Sangwan wrote:OK then for each search - first sort arraylist and then apply binarysearch method on that sorted list.....Right ?
Right.
Sir ! According to my knowledge, Comparator and Comparable interface helps us in SORTING an object from any collection...
That's one thing they're used for.
Specifically, what they do is to define an
order for a set of objects; now that could be used to sort a List, but it can also be used to define the order for datasets that
maintain their objects in a specific sequence (eg, a TreeSet). Hashed collections like HashSet and HashMap work differently: they are only interested in whether objects are
equal() or not.
So: if you're only interested in
searching, chances are a HashMap is what you want; if you also need to have your objects in a specific
order, then you're going to need Comparable or Comparator.
Winston
BTW: Please don't put lots of bolding in your posts because it comes across as
shouting!!. I suggest you read the
KeepItDown (←click) page.
Thanks.