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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:20:58+00:00 2026-05-29T19:20:58+00:00

I have a 2d array containing first name, last name, and a third irrelevant

  • 0

I have a 2d array containing first name, last name, and a third irrelevant piece of data on each row. I need to alphabetize each row based on last name. How can I accomplish this?

I’ve tried using java.util.Arrays.sort(array[0]); but I can only get it to sort one row or one column. I need to keep the first name and last name together and sort by last name.

so say i have this array

String array [][]=new String[3][2];
       array[0][0]="Kyle";
       array[0][1]="Johnson";
       array[1][0]="Drew";
       array[1][1]="Anderson";
       array[2][0]="Jacob";
       array[2][1]="Peterson";

which is build like this

Kyle | Johnson

Drew | Anderson

Jacob| Peterson

and i need it to end up like this

Drew | Anderson

Kyle | Johnson

Jacob| Peterson

  • 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-29T19:21:01+00:00Added an answer on May 29, 2026 at 7:21 pm

    You can use String.compareTo(String) to get the lexicographic ordering of 2 strings and formulate you own function to do that.
    The rules are simple (pseudo code):

    be [s1,d1] // i.e s1 = Kyle, d1 = Johnson
    be [s2,d2]
    if (s1 < s2)  // means "Does s1 should come before s2 lexicographically" ie. s1.compareTo(s2) 
        [s1,d1] < [s2,d2]
    else if (s1 > s2)
        [s2,d2] < [s1,d1]
    else
        if (d1 < d2)
          etc...
    

    see String.compareTo & String.compareToIgnoreCase to understand the return values of these methods

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

Sidebar

Related Questions

Here is my issue. I have an array containing the name of cities that
I have a 1d array containing Nd data, I would like to effectively traverse
I have a 2d array with rows containing an id number, a name string,
I have both matrices containing only ones and each array has 500 rows and
I have a 1D numpy array containing complex numbers (eg. numpy.complex64). I need to
I have an array containing data (ID numbers and data associated with them). The
I've got a multidimensional array containing some id's, stored in keys called 'name'. Each
I have a array containing japanese caracters as well as normal. How do I
I have an array containing a list of files. I want to sort it
Ruby 1.8.6 I have an array containing numerical values. I want to reduce it

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.