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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:35+00:00 2026-06-04T16:15:35+00:00

I am looking to sort an arraylist of arraylist of integers and I require

  • 0

I am looking to sort an arraylist of arraylist of integers and I require help?

I was informed that I need to implement comparator or comparable and then use the collection.sort to sort the list of list in order…

ArrayList<ArrayList<Integer>> g = new ArrayList<ArrayList<Integer>>()

If you look at the list of list as the following example:
C1 – 5,4,10
C2 – 3,2,1
C3 – 7,8,6
First it will be sorted like this:
C1 – 4,5,10
C2 – 1,2,3
C3 – 6,7,8
Then it will be sorted like this
C1 – 1,2,3
C2 – 4,5,6
C3 – 7,8,10
  • 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-04T16:15:37+00:00Added an answer on June 4, 2026 at 4:15 pm

    No error check for null lists, but here it is.

    List<List<Integer>> list = Arrays.asList(Arrays.asList(10, 5, 4), 
            Arrays.asList(3, 2, 1), Arrays.asList(7, 8, 6));
    for (List<Integer> l : list) {
        Collections.sort(l);
    }
    Collections.sort(list, new Comparator<List<Integer>>() {
        public int compare(List<Integer> o1, List<Integer> o2) {
            return o1.get(0).compareTo(o2.get(0));
        }
    });
    System.out.println(list);
    

    With Java 8 it gets even more concise:

    List<List<Integer>> list = Arrays.asList(Arrays.asList(10, 5, 4),
                    Arrays.asList(3, 2, 1), Arrays.asList(7, 8, 6));
    list.forEach(Collections::sort);
    Collections.sort(list, (l1, l2) -> l1.get(0).compareTo(l2.get(0)));
    System.out.println(list);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for how the methods like ArrayList#sort(Closure) are implemented in Groovy. I've
I am looking for some sort of tool which does not necessarily need to
I am looking to sort the related objects that show up when editing an
i have a collection of objects and i am looking to sort by a
I am looking to implement a sort feature for my address book application. I
I'm looking for some sort of tool that can take an html document and
I'm looking for some sort of module (preferably for python) that would allow me
I have created a custom Comparator to sort an ArrayList of Strings. I have
I'm looking for some sort of very basic privilege escalation example that I can
I am looking for some sort of a free JavaScript/JQuery graphing library that has

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.