Class CharSequenceComparator

  • All Implemented Interfaces:
    java.util.Comparator<java.lang.CharSequence>

    public class CharSequenceComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.CharSequence>
    A Comparator implementation for comparing CharSequence objects.

    This class provides a consistent and null-safe comparison mechanism for CharSequence instances, primarily designed to be used in sorting and ordering operations.

    Example Usage

    
     List<CharSequence> sequences = Arrays.asList("apple", "banana", "apple", null);
     Collections.sort(sequences, CharSequenceComparator.INSTANCE);
     

    The comparison is based on lexicographical ordering similar to String.compareTo(String). Null values are considered smaller than non-null values. When both sequences are null, they are considered equal.

    Since:
    1.0.0
    Author:
    Mercy
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.CharSequence c1, java.lang.CharSequence c2)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Method Detail

      • compare

        public int compare​(java.lang.CharSequence c1,
                           java.lang.CharSequence c2)
        Specified by:
        compare in interface java.util.Comparator<java.lang.CharSequence>