java.util.concurrent.concurrentnavigablemap
接口是concurrentmap
接口的子接口,并且支持navigablemap
操作,并且对其可导航子映射和近似匹配进行递归。
序号 | 方法 | 描述 |
---|---|---|
1 | navigableset<k> descendingkeyset() |
返回此映射中包含的键的相反顺序的navigableset 视图。 |
2 | concurrentnavigablemap<k,v> descendingmap() |
返回此映射中包含的映射的反向排序视图。 |
3 | concurrentnavigablemap<k,v> headmap(k tokey) |
返回该映射的部分键严格小于tokey 的视图。 |
4 | concurrentnavigablemap<k,v> headmap(k tokey, boolean inclusive) |
返回该映射的部分视图,其键值小于(或等于,如果包含值为true )tokey 。 |
5 | navigableset<k> keyset() |
返回此映射中包含的键的navigableset 视图。 |
6 | navigableset<k> navigablekeyset() |
返回此映射中包含的键的navigableset 视图。 |
7 | concurrentnavigablemap<k,v> submap(k fromkey, boolean frominclusive, k tokey, boolean toinclusive) |
返回此映射部分的视图,其键范围从fromkey 到tokey 。 |
8 | concurrentnavigablemap<k,v> submap(k fromkey, k tokey) |
返回此映射,其键从fromkey (包括)到tokey 所述部分的视图。 |
9 | concurrentnavigablemap<k,v> tailmap(k fromkey) |
返回此映射的部分视图,其键值大于或等于fromkey 。 |
10 | concurrentnavigablemap<k,v> tailmap(k fromkey, boolean inclusive) |
从映射返回一个键大于(或等于,包含值为true )部分的视图。 |
以下testthread
程序显示了基于线程的环境中concurrentnavigablemap
接口的使用。
import java.util.concurrent.concurrentnavigablemap;
import java.util.concurrent.concurrentskiplistmap;
public class testthread {
public static void main(final string[] arguments){
concurrentnavigablemap<string,string> map = new concurrentskiplistmap<string, string>();
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}