public enum CharSequenceComparator extends Enum<CharSequenceComparator> implements Comparator<CharSequence>
CharSequence.
This comparator can be used, for instance, in sorting lists or performing binary searches where the elements are CharSequence instances. It performs a lexicographic comparison character by character.
Example:
// Sorting a list of data objects based on CharSequence id before marshalling.
dataList.sort(comparing(Data::getId, CharSequenceComparator.INSTANCE));
// Finding an index within a sorted list based on a CharSequence key.
int index = binarySearch(dataList, Data::getId, "DEF", CharSequenceComparator.INSTANCE);
CharSequence,
Comparator| Enum Constant and Description |
|---|
INSTANCE
The singleton instance of CharSequenceComparator.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compare(@NotNull CharSequence o1,
@NotNull CharSequence o2)
Compares two
CharSequence instances lexicographically. |
static CharSequenceComparator |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static CharSequenceComparator[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOfcomparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic static final CharSequenceComparator INSTANCE
public static CharSequenceComparator[] values()
for (CharSequenceComparator c : CharSequenceComparator.values()) System.out.println(c);
public static CharSequenceComparator valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic int compare(@NotNull
@NotNull CharSequence o1,
@NotNull
@NotNull CharSequence o2)
CharSequence instances lexicographically.
Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second, respectively.
compare in interface Comparator<CharSequence>o1 - The first CharSequence to be compared.o2 - The second CharSequence to be compared.AssertionError - if an IndexOutOfBoundsException occurs, indicating a bug.Copyright © 2024. All rights reserved.