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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:21:10+00:00 2026-06-14T12:21:10+00:00

Here is the question: Java sort based on two columns But, can anyone explain

  • 0

Here is the question:

Java sort based on two columns

But, can anyone explain how to do without using Comparator? In other words, How the comparator works internally for sorting multiple columns?

  • 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-14T12:21:11+00:00Added an answer on June 14, 2026 at 12:21 pm

    The sort method must have some way of finding out the relative order of pairs of rows. There are two supported ways of doing it using the normal sorts. Either use instances of a class that implements Comparable to represent rows, or use a Comparator.

    If you don’t want to do either of those, you would have to write your own, specialized, sort method. When it needs to compare two rows, it would look first at the higher priority column. If the rows differ in that column, that gives there order. If they are equal in that column, order them based on the second column.

    That said, using a standard sort with either Comparable rows or a Comparator is much better than mixing up the sort logic and the comparison logic. Comparator is the more flexible way.

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

Sidebar

Related Questions

First question here: it is a very short yet fundamental thing in Java that
Total noobie question here. I'm just learning Java, and studying passing arguments to functions.
I've posted the same question here a few days ago( Java reading standard output
I have some question over here regarding the java garbage collector. First let me
I mostly write in C but am using Java for this project. I want
This is a real beginner question (I'm still learning the Java basics). I can
Here is a link to a similar question with a good answer: Java Algorithm
I have question regarding Java Comparator. Or maybe you all have another Idea to
This is, what I think is a basic java question here: This is for
I'd have a question here considering java generics. I have a generic class called

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.