I am new to java.
I want to sort a concurrent hash map by value. I found a way of doing it here –
sort concurrent map entries by value
Is there a simpler way of doing it? Can someone please explain it with an example ?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Another solution would be to switch to using the
ConcurrentSkipListMapwhich was added in Java 6. To quote from the Javadocs:SkipLists are probabilistic replacements for balanced trees. They have the same
Oas trees but usually their implementation is markedly simpler. If most of your operations are hash-table lookups (O(1)by definition) then you will see a performance different for decent table sizes, but if you require sorting often, this may be a better solution.I just wish Java provided a non-concurrent version of this great data structure.