Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Concurrent HashMap

Tags:

java

i want to convert a ConcurrentHashMap to a TreeMap.Can i do that?

like image 798
Jony Avatar asked Dec 12 '25 04:12

Jony


2 Answers

If you need a Sorted ConcurrentMap look at ConcurrentSkipListMap. Considering its complexity it is both non blocking and fast. To be more specific:

This class implements a concurrent variant of SkipLists providing expected average log(n) time cost for the
containsKey, get, put and remove operations and their variants.

like image 126
John Vint Avatar answered Dec 14 '25 20:12

John Vint


A ConcurrentHashMap is still a Map. So you can create a new TreeMap like this:

ConcurrentHashMap myMap;
...
TreeMap myTreeMap = new TreeMap( myMap );
like image 45
tangens Avatar answered Dec 14 '25 19:12

tangens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!