Sort on a string that may contain a number

前端 未结 23 2080
走了就别回头了
走了就别回头了 2020-11-22 02:59

I need to write a Java Comparator class that compares Strings, however with one twist. If the two strings it is comparing are the same at the beginning and end of the strin

23条回答
  •  自闭症患者
    2020-11-22 03:49

    The Alphanum Algorithm

    From the website

    "People sort strings with numbers differently than software. Most sorting algorithms compare ASCII values, which produces an ordering that is inconsistent with human logic. Here's how to fix it."

    Edit: Here's a link to the Java Comparator Implementation from that site.

提交回复
热议问题