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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:52:56+00:00 2026-06-11T19:52:56+00:00

I have created a HashMap object which stores a String as key and corresponding

  • 0

I have created a HashMap object which stores a String as key and corresponding value as int. Now I want to have a Priority Queue which have all the String present in HashMap object with value as reference for assigning priorities. I have written the following code

public class URIQueue {

      private HashMap<String,Integer> CopyQURI;
      private PriorityQueue<String> QURI;

      public class TComparator<String> {
         public int compareTo(String s1, String s2) {
            if (CopyQURI.get(s2) - CopyQURI.get(s1) >= 0) {
               return 1;
            } else {
               return 0;
            }
         }
      }

      public URIQueue() {
         CopyQURI=new HashMap<>(100);
         TComparator<String> tc=new TComparator<>();
         QURI=new PriorityQueue<>(100, tc); //Line x
      }
 }

Line x is showing error cannot infer type argument for priority queue. Please guide me what mistake I have done.

  • 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-11T19:52:57+00:00Added an answer on June 11, 2026 at 7:52 pm

    The error you are referring to states, that it cannot guess the generic type parameter which you have omitted. The reason for that is that the constructor you are using is not known. It is not known, because you second argument is not a comparator. Your comparator has to implement the java.util.Comparator interface in order to be type safe for the constructor to accept.

    public class TComparator<String> implements Comparator<String> {
    
       @Override
       public int compare(String arg0, String arg1) {
          // ...
       }
    }
    

    Also mind, in the Comparator interface the appropriate method is called compare and not compareTo.

    A general advice, I have to agree with Louis Wasserman, for two given arguments a comparator should always return the same result and not depend on the state of the application. It’s just too easy not to think of some case and the application is eventually flawed.

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

Sidebar

Related Questions

I would like to have a HashMap with only one key-value object. I have
I have a hashmap containing objects created via a constructor. These objects are in
I have an object Line which contains 2 objects of type Point called Point1
I have created custom result class to serialize json data to xml. I want
class MyThing { protected HashMap<String,Object> fields; protected MyThing(HashMap<String,Object> newFields){ fields.putAll(newFields); } protected Object get(String
I have declared the following method: private void mockInvokeDBHandler(Map<String, Object>... rows) { List<Map<String, Object>>
I want to create a hashmap of classes like (Object.class). I am wondering whether
after I create a new object : Map<Float,Integer> m = new HashMap()<Float,Integer>; I have
I have a problem with a HashMap I have created. When I go to
I have the created a sample Lucene code snippet which indexes a small file.

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.