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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:13:48+00:00 2026-06-01T14:13:48+00:00

I have a two-dimension ArrayList that contains double values: ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>();

  • 0

I have a two-dimension ArrayList that contains double values:

ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>(); 

In analogy with classic arrays , I would like to sort the “cols” of this matrix :I want to take the items having the same index in the sub ArrayLists, and then sort them. Like calling Collections.sort() for every column…
By rows I mean the outer level and inner level are columns.

What is the proper way to do this?
I thought about iterating over the matrix to invert it and then sort each row with Collections.sort() ? but maybe it’s not the best solution because the matrix is about 400*7000 .

I can’t use classic arrays since the size of the matrix is unknown.

Thanks for help.

  • 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-01T14:13:49+00:00Added an answer on June 1, 2026 at 2:13 pm

    Do something like this:

        final int COLUMN = 5;
        Comparator<ArrayList<Double>> myComparator = new Comparator<ArrayList<Double>>() {
            @Override
            public int compare(ArrayList<Double> o1, ArrayList<Double> o2) {
                return o1.get(COLUMN).compareTo(o2.get(COLUMN));
            }
        };
        Collections.sort(list, myComparator);
    

    Set COLUMN to whatever column you’re sorting on.

    Update:

    Yes, this won’t work at all.

    I like ahanin’s second suggestion to make your own List which wraps your original List. You would have to wrap the object returned by get() as well so that the variable wrappedList contains the column values and wrappedList.get(0) also returns a column of values. Then the sorting can work. I wonder what the minimum methods are that you have to implement for Collections.sort() to work on your List.

    It would probably be easiest to just take someone else’s quicksort and make it work with your list.

    Here is one implementation: http://www.vogella.de/articles/JavaAlgorithmsQuicksort/article.html

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

Sidebar

Related Questions

I have an two dimension array that contains strings and want to create a
I have a two dimensional ArrayList that I need to filter the duplicates out
I have a two dimensional array that I need to load data into. I
I have a graph class that employs two dimension vertices using a map with
I have a dimension (SiteItem) has two important facts: perUserClicks perBrowserClicks however, within this
I have two div elements that are twins (i.e. their dimensions and contents are
I have a two-dimensional array (of Strings) which make up my data table (of
I have a two dimensional JSON array where each element contains several attributes. The
I have two-dimension array List<List<int>> boardArray How can I enumerate throw this array to
I have two arrays. Example of the first array: $arrayOne = array ( 'fruit'

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.