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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:36:59+00:00 2026-06-15T08:36:59+00:00

I have code: List<ModelMap> nameCustomer = new ArrayList<ModelMap>(); for (int i=1;i<150;i++) { ModelMap map

  • 0

I have code:

    List<ModelMap> nameCustomer = new ArrayList<ModelMap>();

    for (int i=1;i<150;i++) {
                    ModelMap map = new ModelMap();
                    map.put("name", "nazwa " + i);
                    map.put("surname", "nazwisko " + i);
                    map.put("number", "123 ");
                    nameCustomer.add(map);
                }

            ModelMap[] result = new ModelMap[nameCustomer.size()];
            ModelMap[] rowsArray = nameCustomer.toArray(result);

How can I sort nameCustomer (or rowsArray) by surname or number?

  • 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-15T08:37:00+00:00Added an answer on June 15, 2026 at 8:37 am

    You can use the Collections.sort(nameCustomer, comparator) method to sort your list. For that you have to write the code for your Comparator.The code for Comparator will be –

    public Comparator<ModelMap> getComparator(final String sortBy){
       if ("surname".equals(sortBy)) {
       return new Comparator<ModelMap>() {
       @Override int compare(ModelMap m1, ModelMap m2) 
        return m1.getSurname().compareTo(m2.getSurname());
       }};} 
         else if (condition) {// ...  }
          else {
            throw new IllegalArgumentException("invalid sort field '" + sortBy + "'"); }
           }
    

    I am assuming that you have a getSurname method written in your ModelMap class to get the surname. If not then write it to make the above code work.

    You can visit here for further help. Cheers !!

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

Sidebar

Related Questions

I have the following code: List<int> intList = new ArrayList<int>(); for (int index =
I have this code: List<Runnable> r = new ArrayList<>(); for(int i = 0; i
i have this code: var list = new List<int>(); for(int i=0;i<10;i++) list.Add(i); for(int i=0;i<10;i++)
I have this piece of code List<Class<? extends SubApplication>> appClasses = new ArrayList<Class<? extends
I have the below java code: List<SomePojo> list = new ArrayList<SomePojo>(); //add 100 SomePojo
I have the following C# code: List<int[,]> l1 = new List<int[,]>(); l1[0] = new
I have very simple code: List<String> list = new ArrayList<String>(); String a = a;
I have code: List<String> list = new ArrayList<String>(); list.add(10.160.0.100;14/Nov/201107:22:38;/;-;); list.add(10.160.0.100;14/Nov/201108:54:31;/;-;); list.add(10.160.0.10;16/Nov/201112:56:38;/;-;); list.add(10.160.0.100); list.add(10.160.0.100); list.add(10.160.0.10);
I have this code: List<int> list = new List<int>(); for (int i = 1;
i have this code: ArrayList list = new ArrayList(); foreach (DataRow dataR in prenume.Rows)

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.