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, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic int compare(Object o1, Object o2)
compare in interface Comparatorpublic boolean equals(Object obj)
equals in interface Comparatorequals in class ObjectCopyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.