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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:58:59+00:00 2026-05-26T08:58:59+00:00

I know how to sort an array that has two columns: Arrays.sort(myarray, new Comparator<String[]>()

  • 0

I know how to sort an array that has two columns:

Arrays.sort(myarray, new Comparator<String[]>() {
                     @Override
                     public int compare(String[] entry1, String[] entry2) {
                         String time1 = entry1[0];
                         String time2 = entry2[0];
                         return time2.compareTo(time1);
                     }
                });

This sorts the arrray by the first column.
But what if I have more columns? E.g.

myarray[0][0]= +3620205252
myarray[0][1]= 32534
myarray[0][2]= Franco Nera
myarray[0][3]= 183
myarray[1][0]= +3658300234
myarray[1][1]= 4334
myarray[1][2]= Judy Moira
myarray[1][3]= 28

etc..
I want to sort this e.g. by the second column, or the fourth column…
I can try to work this out by creating a new array[1st+3rd+4th column][2nd column] and then sort it with the above solution, then take the elements apart, but that is too circumstantial.

  • 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-26T08:59:00+00:00Added an answer on May 26, 2026 at 8:59 am

    It’s the same thing as with two columns, but with more columns: you can sort on as many, or as few, columns as you want, as long as your comparator checks the columns you care about.

    To sort by multiple columns you need to decide the comparison order and return the compareTo result as soon as you have unequal columns.

    Tangentially, why would you use arrays for this? It’s Java, might as well use like an object or something.

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

Sidebar

Related Questions

I'm trying to sort a multidimensional array in objective-c i know that i can
does anyone know any sort of app that lets users visit a page on
I know that JTable can sort by a single column. But is it possible
I know VS2008 has the remove and sort function for cleaning up using directives,
I have a line in a javascript function that sort an array of objects
I've a model object that extends from NSObject called column. Column has two fields,
I know something like this has been asked before, but the answer was sort
I have a huge array of ints that I need to sort. The catch
Trying to get the highest and lowest value from an array that I know
I've looked around the web and know that one of the ways to sort

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.