📅  最后修改于: 2020-11-15 04:01:01             🧑  作者: Mango
java.util.concurrent.ConcurrentNavigableMap接口是ConcurrentMap接口的子接口,并且支持NavigableMap操作,并对其递归的子地图和近似匹配进行递归。
Sr.No. | Method & Description |
---|---|
1 |
NavigableSet Returns a reverse order NavigableSet view of the keys contained in this map. |
2 |
ConcurrentNavigableMap Returns a reverse order view of the mappings contained in this map. |
3 |
ConcurrentNavigableMap Returns a view of the portion of this map whose keys are strictly less than toKey. |
4 |
ConcurrentNavigableMap Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey. |
5 |
NavigableSet Returns a NavigableSet view of the keys contained in this map. |
6 |
NavigableSet Returns a NavigableSet view of the keys contained in this map. |
7 |
ConcurrentNavigableMap Returns a view of the portion of this map whose keys range from fromKey to toKey. |
8 |
ConcurrentNavigableMap Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. |
9 |
ConcurrentNavigableMap Returns a view of the portion of this map whose keys are greater than or equal to fromKey. |
10 |
ConcurrentNavigableMap Returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey. |
下面的TestThread程序显示ConcurrentNavigableMap的用法。
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
public class TestThread {
public static void main(final String[] arguments) {
ConcurrentNavigableMap map =
new ConcurrentSkipListMap();
map.put("1", "One");
map.put("2", "Two");
map.put("3", "Three");
map.put("5", "Five");
map.put("6", "Six");
System.out.println("Initial ConcurrentHashMap: "+map);
System.out.println("HeadMap(\"2\") of ConcurrentHashMap: "+map.headMap("2"));
System.out.println("TailMap(\"2\") of ConcurrentHashMap: "+map.tailMap("2"));
System.out.println(
"SubMap(\"2\", \"4\") of ConcurrentHashMap: "+map.subMap("2","4"));
}
}
这将产生以下结果。
Initial ConcurrentHashMap: {1 = One, 2 = Two, 3 = Three, 5 = Five, 6 = Six}
HeadMap("2") of ConcurrentHashMap: {1 = One}
TailMap("2") of ConcurrentHashMap: {2 = Two, 3 = Three, 5 = Five, 6 = Six}
SubMap("2", "4") of ConcurrentHashMap: {2 = Two, 3 = Three}