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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:22:27+00:00 2026-05-26T00:22:27+00:00

I have a TreeTable and would like to perform the sort by number and

  • 0

I have a TreeTable and would like to perform the sort by number and alphabetically when clicking on header.

Example:

  • On a first click, I have to check that the column content is sorted by number
  • If I click on another column that contains String data, I have to check that column content is sorted alphabetically.

Are there known functions that could I use?

I’ve used Collections for sorting number , but how do I can make the sort alphabetically ?
Collections.sor(myList) is OK for sorting by number but I would sort data alphabetically.

thanks

  • 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-26T00:22:29+00:00Added an answer on May 26, 2026 at 12:22 am

    This can easily be done via Collections.sort(...). Create a copy of your list, sort it and check if they are equal.

    Example:

    List <String> copy = new ArrayList <String>(original);
    Collections.sort(copy);
    assertEquals(copy, original);
    

    This can be done, if the elements in the list are comparable (i.e. are of type T implements Comparable <T>). Strings are comparable, and their default comparator sorts them alphabetically (though upper-case are always comes before lower-case)

    You may also provide a Comparator for a more flexible sorting.

    Here is a more complicated example.

    List <String> unholyBible = new ArrayList <String>();
    unholyBible.add("armageddon");
    unholyBible.add("abyss");
    unholyBible.add("Abaddon");
    unholyBible.add("Antichrist");
    Collections.sort(unholyBible);
    System.out.println(unholyBible);
    

    This will print us [Abaddon, Antichrist, abyss, armageddon]. This is because default comparation is case-sensitive. Lets fix it:

    List <String> unholyBible = new ArrayList <String>();
    unholyBible.add("armageddon");
    unholyBible.add("abyss");
    unholyBible.add("Abaddon");
    unholyBible.add("Antichrist");
    Collections.sort(unholyBible, new Comparator <String>() {
        public int compare(String o1, String o2){
            return o1.compareToIgnoreCase(o2);
        }
    });
    System.out.println(unholyBible);
    

    This one prints [Abaddon, abyss, Antichrist, armageddon].

    Now you may worship Satan in strict alphabetical order.

    See also

    • Comparator API
    • Collections.sort(List, Comparator)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a treeview that renders as tables. The html would be something like:
I have a page operation that uses something like: $('#thetable tbody').replaceWith(newtbody); in an ajax
I've an MVVM-lite application that I'd like to have unit testable. The model uses
This is my lame first attempt. I would like to get a count of
I have a bit old project that I would call legacy. Some characteristics of
I would like to implement a JTreeTable. I saw the example in the official
I have a number of timetables for a train network that are of the
I have content management system application that uses a polymorphic tree table as the
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have a matrix report now that has Position, Hours and Wages for a location

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.