On Sun, 12 Apr 2009 14:16:38 -0700, Arne Vajh?j <arne@vajhoej.dk>
wrote:
Mike Schilling wrote:
Peter Duniho wrote:
For that matter, maybe there _is_ a List implementation out
there
that allows you to provide a Comparator. I haven't noticed one
built into Java if there is, but it wouldn't be surprising if it
exists somewhere.
What job would a Comparator have in a List?
contains and indexOf using a logic different from the
objects equals.
And lastIndexOf(Object o), remove(Object o),
containsAll(Collection<?> c), removeAll(Collection<?> c), and
retainAll(Collection<?> c), not to mention equals(Object o) and
hashCode(). The fact is, as soon as you start introducing the
concept of
comparing two objects (whether just for equality or a complete
ordering), there is also the possibility of wanting to provide
custom logic for that comparison. Given how many different
operations are possible in a List<E>, it seems perfectly logical to
have a List<E> implementation that allows for a custom Comparator.
Maybe overkill in many situations, but hardly unreasonable.
convenient.
That I don't understand.