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 8855509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:09:07+00:00 2026-06-14T14:09:07+00:00

I have a list of words sorted using g_ascii_strcasecmp function. I need to process

  • 0

I have a list of words sorted using g_ascii_strcasecmp function. I need to process this list in java. What is the equivalent sorting function in java? In order to implement binary search I need a correct comparison function. So far I have the function below but it is not always produces the correct result.

public int compareStrings(String str) {
    Collator collator = Collator.getInstance();//TODO: implement locale?
    return collator.compare(this.wordString, str);
}

UPDATE. List example: “T, t, T’ai Chi Ch’uan, t’other, T-, T-bone, T-bone steak, T-junction, tabasco, Tabassaran, tabby”.

  • 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-14T14:09:09+00:00Added an answer on June 14, 2026 at 2:09 pm

    I decided to share the method I came up with:

        /**
         * Compares two strings, ignoring the case of ASCII characters. It treats
         * non-ASCII characters taking in account case differences. This is an 
         * attempt to mimic glib's string utility function 
         * <a href="http://developer.gnome.org/glib/2.28/glib-String-Utility-Functions.html#g-ascii-strcasecmp">g_ascii_strcasecmp ()</a>.
         *
         * This is a slightly modified version of java.lang.String.CASE_INSENSITIVE_ORDER.compare(String s1, String s2) method.
         * 
         * @param str1  string to compare with str2
         * @param str2  string to compare with str1
         * @return      0 if the strings match, a negative value if str1 < str2, or a positive value if str1 > str2
         */
        private static int compareToIgnoreCaseASCIIOnly(String str1, String str2) {
            int n1 = str1.length();
            int n2 = str2.length();
            int min = Math.min(n1, n2);
            for (int i = 0; i < min; i++) {
                char c1 = str1.charAt(i);
                char c2 = str2.charAt(i);
                if (c1 != c2) {
                    if ((int) c1 > 127 || (int) c2 > 127) { //if non-ASCII char
                        return c1 - c2;
                    } else {
                        c1 = Character.toUpperCase(c1);
                        c2 = Character.toUpperCase(c2);
                        if(c1 != c2) {
                            c1 = Character.toLowerCase(c1);
                            c2 = Character.toLowerCase(c2);
                            if(c1 != c2) {
                                return c1 - c2;
                            }
                        }
                    }
                }
            }
            return n1 - n2;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a list of words, something like this: ['The', 'Quick', 'Brown',
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
I'm trying to implement a sorted list as a simple exercise in Java. To
I have an arraylist<string> of words. I sort it using Collections.sort(wordsList); I'm using this
I have list of words. I type in a word misspelled. Can I query
I have a list of words and i have to find the minimum word
I have a list of words (profanities) blacklisted and I want to retrospectively go
I have a list of words (assume they are stored in String[] if you
As title says, I have a list of words, Like stopWords = [the, and,
I have a list of whitelisted words: kitchen chair table ; Given a text,

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.