Who told you we can't? We can, only this is not the fastest method in the World. For relatively small collections it's perfectly fine. It all depends on your requirements to performance. Also, you should use it with care. See:
http://www.daniweb.com/software-development/java/threads/109506[
^].
As to the speed of the algorithm, it expect it have the
complexity of O(n), that is, linear. (On this notation, see
http://en.wikipedia.org/wiki/Big_O_notation[
^].) A hash table or a dictionary based on hash values and buckets will give you O(1) — approximating a constant time of execution on big collection, that is, with a big collections the time does not depends on the size of collection. So,
IndexOf
is only good for small collections or when you want to save on memory and the search time is still acceptable.
—SA