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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:59:09+00:00 2026-05-22T14:59:09+00:00

In the following code, adding the same letter to both operands of the comparison

  • 0

In the following code, adding the same letter to both operands of the comparison changes the result. Despite - being not greater than j, -k is greater than jk.

This only happens if one of the operands is the minus sign (-) or single quotation mark (').

Why does this happen? What are the rules?

if - gtr j (echo - greater than j) else echo - less than j
if "-" gtr "j" (echo "-" greater than "j") else echo "-" less than "j"
echo.
if -k gtr jk (echo -k greater than jk) else echo -k less than jk
if "-k" gtr "jk" (echo "-k" greater than "jk") else echo "-k" less than "jk"
echo.
if ' gtr u (echo ' greater than u) else echo ' less than u
if "'" gtr "u" (echo "'" greater than "u") else echo "'" less than "u"
echo.
if 'v gtr uv (echo 'v greater than uv) else echo 'v less than uv
if "'v" gtr "uv" (echo "'v" greater than "uv") else echo "'v" less than "uv"

The result is:

- less than j
"-" less than "j"

-k greater than jk
"-k" greater than "jk"

' less than u
"'" less than "u"

'v greater than uv
"'v" greater than "uv"
  • 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-05-22T14:59:10+00:00Added an answer on May 22, 2026 at 2:59 pm

    You may be assuming that strings are just compared character by character, taking their ordinal values.

    That’s not true. Collation is much more complex than that.

    In fact, you can see the same in other environments, such as Windows PowerShell:

    PS Home:\> '-' -gt 'j'
    False
    PS Home:\> '-k' -gt 'jk'
    True
    PS Home:\> '''' -gt 'u'
    False
    PS Home:\> '''v' -gt 'uv'
    True
    

    It could very well be that the order of strings varies with your locale as well.

    As for your particular problem here, quoting from the Unicode Collation Algorithm (UTS #10):

    Collation order is not preserved under concatenation or substring operations, in general.

    For example, the fact that x is less than y does not mean that x + z is less than y + z, because characters may form contractions across the substring or concatenation boundaries. In summary:

    x < y does not imply that xz < yz
    x < y does not imply that zx < zy
    xz < yz does not imply that x < y
    zx < zy does not imply that x < y

    and to solve the misconveption you’re likely under:

    Collation is not code point (binary) order.

    A simple example of this is the fact that capital Z comes before lowercase a in the code charts. As noted earlier, beginners may complain that a particular Unicode character is “not in the right place in the code chart.” That is a misunderstanding of the role of the character encoding in collation. While the Unicode Standard does not gratuitously place characters such that the binary ordering is odd, the only way to get the linguistically-correct order is to use a language-sensitive collation, not a binary ordering.

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

Sidebar

Related Questions

I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() {
I have the following code for adding to/extracting from Zip. I'm trying to refactor
I am using the following code --- EDIT @annakata : Adding the complete code
The following code works great in IE, but not in FF or Safari. I
The following code illustrates an object literal being assigned, but with no semicolon afterwards:
... It's not as silly as it sounds... I have the following code, which
Not sure what is going on. When I perform the following code... it runs
Alternative wording : When will adding Double.MIN_VALUE to a double in Java not result
I' m trying to enable adding/deleting rows to/from table using folowing code: Script: $(document).ready(function()
Following code, when compiled and run with g++, prints '1' twice, whereas I expect

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.