Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8601787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:55:30+00:00 2026-06-12T01:55:30+00:00

I thought this would be easy to find premade, but it seems any solution

  • 0

I thought this would be easy to find premade, but it seems any solution I can find on the web solves only part of the problem.

I want to sort a list of Filenames (and the files have mostly been named after persons and/or addresses) that have been given by users, sometimes in different languages (mostly german, with a bit of french and italian mixed in here and there, and rarely any other western language).

The idea is to present this list ordered in a way that the (german) users generally deem sane. That means the order should follow the java.text.Collator for Locale.GERMAN, but at the same time the expectation is to make an exception for numbers in the string, so “10” comes after “2”.

I have found code to do the natural sorting on the web, but it relies on comparing character by character (and Collator doesn’t support that). I could hack something with substring, but inside a comparator it doesn’t deem me the brightest idea to create multiple substrings on each compare-call.

Any ideas how to implement this efficiently (in both execution time and implementation time), or better yet a tested and ready-to-use implementation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:55:31+00:00Added an answer on June 12, 2026 at 1:55 am

    If you use the Comparator suggested by @millimoose (http://www.davekoelle.com/alphanum.html) modify it to pass the Collator

    public class AlphanumComparator implements Comparator
    {
    private Collator collator;
    public AlphanumComparator(Collator collator) {
        this.collator = collator;
    }
    .....
        public int compare(Object o1, Object o2)
        {
    ......
    result = thisChunk.compareTo(thatChunk); //should become
    collator.compare(thisChuck, thatChuck);
    ....
    

    this code seems to have a problem, for example “01” is grater then “2”. But this depends on you preference, if this is important modify it to skip the leading zeros before number compare.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this would be really easy but I can't find a simple solution,
I thought this would be easy to do but I can't find a way.
I thought this would be an easy question, but I can't find the answer.
I thought this would have been an easy thing to find but I've failed.
I thought this would be easy to find, but a google search has been
This should be obvious, I thought. But I can't find easy way to find
I thought this would be fairly easy, but I'm totally baffled. I want one
I thought this would be pretty easy but I'm running into all sorts of
I would have thought that this would be an easy thing to do, but
Okay at first I thought this would be pretty straightforward. But I can't think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.