Re: ArrayList BinarySearch vs Contains



"tshad" <tscheiderich@xxxxxxxxxxxxxxx> wrote in message
news:u8iJyqQBHHA.4256@xxxxxxxxxxxxxxxxxxxxxxx
Which is better to use with an ArrayList: BinarySearch or Contains?

The list is only going to have strings in it and it will be sorted.

Then BinarySearch is better. Contains will be an O(n) operation always
(since it doesn't know whether the data is sorted), while BinarySearch is an
O(lg(n)) operation. Just make sure that the data really is sorted!

-cd


.