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

  • SEARCH
  • Home
  • 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 6745143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:10:08+00:00 2026-05-26T12:10:08+00:00

What will happen if I supply a non-transitive Comparator to Collections.sort ? Can I

  • 0

What will happen if I supply a non-transitive Comparator to Collections.sort? Can I run into infinite loop?

A small test I wrote produced an output, but I want to make sure this will always be the case.

The problem is that in some cases, my comparator can produce cycles, and in this case I just want to make sure it will not run into infinite loop. I don’t care about the actual result.

  • 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-26T12:10:09+00:00Added an answer on May 26, 2026 at 12:10 pm

    The Java docs say that you must make sure that your comparator is transitive. If you supply a comparator that doesn’t adhere to what was requested, all bets are off. It might work for a given implementation but might crash horribly (std::sort in C++ does) in another.

    In short, you shouldn’t rely on it working even if it does for some or other examples.

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

Sidebar

Related Questions

I'm wondering what will happen on a non-retina display device if only the @2x
In C, what will happen if I supply a signed integer especifically a negative
What will happen if I do the following: I substitute all non-retina assets with
I was wondering what will happen if I run this code: <!DOCTYPE html> <html
Does anyone know what will happen with existing apps when they run on the
What will happen if we will run delete widget for widget that is in
can you explain what will happen if opcode cc or \xcc is in running
if my class is private and constructor is public then what will happen. can
What will happen if I use recv(sockfd, buffer, len, 0); on a non-blocking socket?
What will happen if i have two mirrors with same id in the settings.xml

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.