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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:25:30+00:00 2026-05-18T09:25:30+00:00

How can I create a list (or some other type of container) of integer

  • 0

How can I create a list (or some other type of container) of integer and strings pairs that allows duplicates in both pairs and can be sorted by the integer value?

I need to fill a container with names (string) and scoring (integer) pairs, the container must allow duplicated values in both name and scoring, and i need to sort this list by the scoring value.

I tried with a SortedMap but doesn’t allow duplicated values:

SortedMap<Integer,String> sm=new TreeMap<Integer, String>();

sm.put(23, "Peter");  
sm.put(11, "Tony");  
sm.put(110, "Claire");  
sm.put(13, "ferca");  
sm.put(55, "Julian");  
sm.put(13, "Pedro");  

In this example, ferca and Pedro have the same scoring value, this is something I need to allow, but the SortedMap overwrites “ferca” with “Pedro”.

What is the best container type to do this?

  • 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-18T09:25:31+00:00Added an answer on May 18, 2026 at 9:25 am

    Since you want your collection to be ordered, I suggest you use a List and Collections.sort. If you decide to go for this approach you still have two options:

    • Create a custom Comparator that can be passed as an argument to sort, or
    • Let the auxiliary Score class implement Comparable<Score>

    Here is an example and ideone demo of the latter approach:

    import java.util.*;
    
    class Score implements Comparable<Score> {
        int score;
        String name;
    
        public Score(int score, String name) {
            this.score = score;
            this.name = name;
        }
    
        @Override
        public int compareTo(Score o) {
            return score < o.score ? -1 : score > o.score ? 1 : 0;
        }
    }
    
    public class Test {
    
        public static void main(String[] args){
            List<Score> scores = new ArrayList<Score>();
    
            scores.add(new Score(23, "Peter"));  
            scores.add(new Score(11, "Tony"));  
            scores.add(new Score(110, "Claire"));  
            scores.add(new Score(13, "ferca"));  
            scores.add(new Score(55, "Julian"));  
            scores.add(new Score(13, "Pedro"));
    
            Collections.sort(scores);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can create a Numbered Range List of numeric type, but not character type.
How can I quickly create a List[Int] that has 1 to 100 in it?
Is it possible to create a list that can be access by either an
I know I can create a generic method that I can call from other
Due to validation markup and some other reasons I disable the list-style-type css property
I want to create a system that stores books (and some other documents). Users
I want to create a replacement class of the built-in type set that can
Can you create a list of functions and then execute them sequentially, perhaps passing
How can I create a list in C++? I need it to create a
Is it possible to create a multidimensional list in C#? I can create an

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.