public class StringComparator extends Object implements Comparator
Comparator
interface.
It is suitable for use on any objects for which the toString
method provides a suitable basis for object comparison.
You might think that calling java.text.Collator.getInstance
ought to provide much the same thing; however that gives you a
compare
method which casts to String
rather
than calling the toString
method on its arguments,
leading to a ClassCastException
in most useful cases.
I wonder why it does that?
Constructor and Description |
---|
StringComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compare(Object o1,
Object o2) |
boolean |
equals(Object obj) |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public int compare(Object o1, Object o2)
compare
in interface Comparator
public boolean equals(Object obj)
equals
in interface Comparator
equals
in class Object
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.