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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:59:33+00:00 2026-06-17T02:59:33+00:00

The value type of my map is a List<Pair<Integer, String>> I want to sort

  • 0

The value type of my map is a List<Pair<Integer, String>>

I want to sort it by the left side of first pair in the list. But there is an error said:

The constructor
TreeMap<String,List<Pair<Integer,String>>> (Comparator<List<Pair<Integer,String>>>)
is undefined

Here is my code:

import java.util.TreeMap;
import org.apache.commons.lang3.tuple.Pair;

Map<String, List<Pair<Integer, String>>> data = new HashMap<String, List<Pair<Integer,String>>>();  
            ....
Comparator<List<Pair<Integer, String>>> valueComparator = new Comparator<List<Pair<Integer, String>>>() {
            @Override
            public int compare(List<Pair<Integer, String>> o1,
                    List<Pair<Integer, String>> o2) {
                int rzt = o1.get(0).getLeft() - o2.get(0).getLeft();
                return rzt;
            }  
           };

           TreeMap<String, List<Pair<Integer, String>>> sortedByValues = new TreeMap<String, List<Pair<Integer, String>>>(valueComparator);
           sortedByValues.putAll(data);
  • 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-17T02:59:34+00:00Added an answer on June 17, 2026 at 2:59 am

    The Comparator should compare keys and not values. The constructor of TreeMap has the following signature:

    public TreeMap(Comparator<? super K> comparator)
    

    where K is the type parameter of the Key: Class TreeMap<K,V>

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

Sidebar

Related Questions

want to know why String behaves like value type while using ==. String s1
Is string a value type or a reference type? I just can't find a
.NET I want to clone a value type's fields. How can i set a
Does anyone know how to convert the string value type -4,5 or 5,4 into
I want to create a generic function that takes any Map & a String
We have a number of Scala classes returning Map[String,String] (key,value) results for storage in
The following code public List<Map<String,String>> getPhoneData() { List<Map<String, String>> mapp = new List<Map<String, String>>();
I have a Scala value of type Option[Set[String]] that I am trying to use
I want to write a map-like object type in PL/SQL. What I mean is
I use @XmlJavaTypeAdapter to transform Map<String, MapItem> objects into List<MapItem> when marshalling (and vice

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.