Java并发 专题
您的位置:java > Java并发专题 > Java并发ConcurrentNavigableMap接口
Java并发ConcurrentNavigableMap接口
作者:--    发布时间:2019-11-20

java.util.concurrent.concurrentnavigablemap接口是concurrentmap接口的子接口,并且支持navigablemap操作,并且对其可导航子映射和近似匹配进行递归。

concurrentnavigablemap接口中的方法

序号 方法 描述
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) 返回此映射部分的视图,其键范围从fromkeytokey
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}

网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册