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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:36:24+00:00 2026-06-11T09:36:24+00:00

I used this method to sorting my hash function. When I compile the program,

  • 0

I used this method to sorting my hash function. When I compile the program, these errors appear:

Note: Retriever.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

My hashMap<String, Double>

private static Map sortByComparator(Map unsortMap) {

    List list = new LinkedList(unsortMap.entrySet());

    // sort list based on comparator
    Collections.sort(list, new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            return ((Comparable) ((Map.Entry) (o2)).getValue())
                    .compareTo(((Map.Entry) (o1)).getValue());
        }
    });

    // put sorted list into map again
    Map sortedMap = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        sortedMap.put(entry.getKey(), entry.getValue());
    }
    return sortedMap;
}
  • 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-11T09:36:25+00:00Added an answer on June 11, 2026 at 9:36 am

    That is a compiler warning because you are ignoring the generics and using “raw” types. Ypu need to specify the generics as follows:

    private static <K, V extends Comparable<V>> Map<K, V> sortByComparator(Map<K, V> unsortMap) {
    
        List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(unsortMap.entrySet());
    
        //sort list based on comparator
        Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
            @Override
             public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
               return o1.getValue().compareTo(o2.getValue());
             }
        });
    
        //put sorted list into map again
        Map<K, V> sortedMap = new LinkedHashMap<K, V>();
        for (Iterator<Map.Entry<K, V>> it = list.iterator(); it.hasNext();) {
             Map.Entry<K, V> entry = it.next();
             sortedMap.put(entry.getKey(), entry.getValue());
        }
        return sortedMap;
    }
    

    What’s going on here, is that by specifying the generic types you’re telling the compiler what types of objects these collections contain. Because of this I’ve been able to eliminate all the casts in the comparator and second loop. This makes the method actually type safe and checkable by the compiler.

    What the compiler is telling you with the warning is that because you’re using raw types and casting it can’t check the accuracy of your typing. The other option is to simply suppress this warning using @SuppressWarnings but it’s better to actually make the method type safe.

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

Sidebar

Related Questions

I have a problem when call applet method from javascript.. I used this function
Basically I've written this program to check for strings. I've used socket method for
Till this moment I used this method to invoke: public string AddText { set
public boolean requestRouteToHost (int networkType, int hostAddress) This method in ConnectivityManager if used with
All, I have a method that returns a List. This method is used to
So, let's say I've got a method like this, which is used to check
This is how I used to make method calls: SvcHelper.Using<SomeWebServiceClient>(proxy => { proxy.SomeMethod(); }
I was reading this answer and trying to copy the method used there, but
I have written a login form, in this I have used, form and method
Is it a bug? I remember to have used this method successfully in the

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.