Class AlphanumComparator

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

    public class AlphanumComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.String>
    This is an updated version with enhancements made by Daniel Migowski, Andre Bogus, and David Koelle. Updated by David Koelle in 2017.

    To use this class: Use the static "sort" method from the java.util.Collections class: Collections.sort(your list, new AlphanumComparator());

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean doCaseSensitive  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.String s1, java.lang.String s2)  
      static void main​(java.lang.String[] args)
      Shows an example of how the comparator works.
      • 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
    • Field Detail

      • doCaseSensitive

        protected final boolean doCaseSensitive
    • Constructor Detail

      • AlphanumComparator

        public AlphanumComparator()
      • AlphanumComparator

        public AlphanumComparator​(boolean caseSensitive)
    • Method Detail

      • compare

        public int compare​(java.lang.String s1,
                           java.lang.String s2)
        Specified by:
        compare in interface java.util.Comparator<java.lang.String>
      • main

        public static void main​(java.lang.String[] args)
        Shows an example of how the comparator works. Feel free to delete this in your own code!