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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:33:20+00:00 2026-06-02T03:33:20+00:00

Hi I currently have 4 arrays all holding different data the issue i have

  • 0

Hi I currently have 4 arrays all holding different data the issue i have run into is that i want to sort one of the arrays alphabetically which normally i would just do like this

class IgnoreCaseComparator implements Comparator<String> {
   public int compare(String strA, String strB) {
      return strA.compareToIgnoreCase(strB);
   }
}
IgnoreCaseComparator icc = new IgnoreCaseComparator();
java.util.Collections.sort(ARRAY,icc);

Where ARRAY would be the array I want to sort Alphabetically however I need the arrays to sort together.

So for example lets say my arrays look like this

Pet Array: [Dog, Cat, Bird]
Owner Array: [Jim, Kyle, Joe]
Friend Array: [Jake, Jim, John]
Cat Array: [false, true, false]

And i want to sort based on Pet Array my output should be like this where all of the third values are now the first and the first values are now the third (This is way over simplified my actual arrays contains thousands of inputs)

Pet Array: [Bird, Cat, Dog]
Owner Array: [Joe, Kyle, Jim]
Friend Array: [John, Jim, Jake]
Cat Array: [false, true, false]

Is there an easy way to do this where i can sort one array and have the others follow. Thank you for any help with this issue.

===EDIT===

Other than my solution being slightly different cause i did a little reading the checked answer is perfect i only have a slightly different return line in the compareTo method

    class Entity implements Comparable<Entity> {
        String Pet;
        String Owner;
        String Friend;
        int Cat;

        Entity(String Pet, String Owner, String Friend, int Cat) {
          this.Pet = Pet;
          this.Owner = Owner;
          this.Friend = Friend;
          this.Cat = Cat;
        }

        @Override
        public int compareTo(Entity other) {
            return this.Pet.compareToIgnoreCase(other.Pet);
        }
     }
  • 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-02T03:33:21+00:00Added an answer on June 2, 2026 at 3:33 am

    You can declare an object:

    class Entity implements Comparable<Entity> {
        Pet pet;
        Person owner;
        Friend friend;
        boolean cat;
    
        Entity(Pet pet, Person owner, Friend friend, boolean cat) {
          this.pet = pet;
          this.owner = owner;
          this.friend = friend;
          this.cat = cat;
        }
    
        public int compareTo(Entity b) {
          return pet.getName().compareToIgnoreCase(b.pet.getName());
        }
     }
    

    Then build an array or a list of these objects. And the sort.

    Entity[] array = new Entity[pets.length];
    for (int i = 0; i < pets.length) {
        array[i] = new Entity(pets[i], owners[i], friends[i], cats[i]);
    }
    Arrays.sort(array);
    

    After that you can split it back to arrays.

    for (int i = 0; i < pets.length) {
        pets[i] = array[i].pet;
        owners[i] = array[i].owner;
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have two arrays one the stores a file name and another that
I currently have a statement which reads if(Arrays.asList(results).contains(Word)); and I want to add at
I have a (C#) genetic program that uses financial time-series data and it's currently
I have 2 arrays that I want to merge based on a key's value
I have the following script currently, which gets the category IDs as arrays: $sql_select_categories
Currently I have an Array that is having 9 buttons pushed to it. This
I have an API call that returns a byte array. I currently stream the
I am currently trying to pass an array that I have created in Javascript
I am currently using markercluster plugin with jquery ui maps. I have two arrays
I currently have a data model set up where each School object has a

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.