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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:11:09+00:00 2026-05-23T17:11:09+00:00

I am using java trying to create a program. What I am trying to

  • 0

I am using java trying to create a program.

What I am trying to do is sort arraylist and then sort a seperate array with the same order. I know how to sort an arrylist but the problem is I have a seperate array where each element is related to an element in the arraylist.

for example here is a possible situation:

String[] array = {"U R F", "B' F2", "L' D"}  
arraylist<Double> = {"2.03", "4.32", "1.23"}

(I know that an arraylist isn’t initialized like that I did it for simplicity)

What I want to end up with is this:

String[] array = {"L' D", "U R F", "B' F2"}  
arraylist<Double> = {"1.23", "2.03", "4.32"}

With the array and arraylist sorted by arraylist numerically.

  • 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-23T17:11:09+00:00Added an answer on May 23, 2026 at 5:11 pm

    As long as your companion array contains unique values, you can build a SortedMap whose key-value pairs are made from the ArrayList and the Array respectively. Read out the values of the SortedMap in order into the resulting array.

    Here is a complete example:

    import java.util.Arrays;
    import java.util.List;
    import java.util.Map;
    import java.util.SortedMap;
    import java.util.TreeMap;
    
    /**
     * Not great code; it just illustrates an idea.
     */
    public class SortExample {
    
        /**
         * Shows how to sort an array based on the way a "companion" list
         * would sort.  <strong>ASSUMPTION</strong>: The values in the companion
         * list must be unique!
         */
        public static void main(String[] args) {
    
            String[] names = {"two", "seven", "six", "eight", "one"};
            List<Integer> numbers = Arrays.asList(2, 7, 6, 8, 1);
    
            // Note: This only works if names and numbers are the same size....
            SortedMap<Integer, String> pairs = new TreeMap<Integer, String>();
            for (int i = 0; i < names.length; i++) {
                pairs.put(numbers.get(i), names[i]);
            }
    
            // Note: This destroys the original array
            int i = 0;
            for (Map.Entry<Integer, String> e : pairs.entrySet()) {
                names[i++] = e.getValue();
            }
    
            System.out.println(Arrays.toString(names));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a Palindrome program using recursion within Java but I
I am trying to create Java Virtual Machine in a cplusplus program using the
I am trying to create a java gui using netbeans but the swing panels
I am trying to create a simple chat program using Java. I have create
I am trying to create my first GUI application using (Java + Eclipse +
I am using Java 6 and am trying to create an HttpsURLConnection against a
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I created an audio Player using java applet but i'm stuck at trying to
I'm trying to create a Java Tool by using Xcode. I've already changed my
I'm trying to create a Java program that is a front-end for iptables. To

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.