java.util.TreeMap.headMap()方法实例
来源:互联网 发布:tower与其他软件 编辑:程序博客网 时间:2024/05/02 21:29
headMap(K toKey) 方法用于返回此映射的键严格小于toKey的部分视图。
声明
以下是java.util.TreeMap.headMap()方法的声明。public SortedMap<K,V> headMap(K toKey)
参数
toKey--这是在返回映射中键的高端点(不包括)。返回值
在方法调用返回此映射的键严格小于toKey部分视图。
异常
ClassCastException-- 抛出此异常如果toKey与此映射的比较兼容(如果该映射没有比较器,如果toKey没有实现Comparable)。实现方式可以,但不要求,抛出此异常,如果toKey不能键进行比较,在当前映射上。
NullPointerException-- 抛出此异常如果toKey为null,并且此映射使用自然排序,或者其比较器不允许使用null键。
IllegalArgumentException-- 这个异常被抛出,如果此映射本身有范围限制,并且toKey位于范围的边界之外。
例子
下面的示例演示java.util.TreeMap.headMap()方法的用法。
import java.util.SortedMap;import java.util.TreeMap;public class TreeMapDemo {public static void main(String[] args) {TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();SortedMap<Integer, String> treemaphead = new TreeMap<Integer, String>();treemap.put(2, "two");treemap.put(1, "one");treemap.put(3, "three");treemap.put(6, "six");treemap.put(5, "five");treemaphead = treemap.headMap(4);System.out.println("checking value of the sorted map");System.out.println("Value is :"+treemaphead );}}
现在编译和运行上面的代码示例,将产生以下结果。
checking value of the sorted mapValue is :{1=one, 2=two, 3=three}
【转自】http://www.yiibai.com/java/util/treemap_headmap.html
0 0
- java.util.TreeMap.headMap()方法实例
- java.util.TreeMap
- java.util.TreeMap源码解析
- java.util.Collections.swap()方法实例
- java.util.Date.getTime()方法实例
- java.util.Properties.getProperty()方法实例
- java.util.ArrayList.toArray(T[]) 方法实例
- java.util.IdentityHashMap.entrySet()方法实例
- java.util.HashMap.remove()方法实例
- java.util.Collections.unmodifiableMap()方法实例
- java.util.Properties.getProperty()方法实例
- java.util.Collections.synchronizedSet()方法实例
- Java.util.Calendar.add()方法实例
- java.util.Calendar.getTime()方法实例
- java.util.Collections.max()方法实例
- java.util.Collections.synchronizedMap()方法实例
- java.util.Collections.unmodifiableList()方法实例
- java.util.Collections.reverseOrder()方法实例
- Eclipse下设置javah命令快捷键
- 利用简单工厂模式设计一个计算器
- 鏖战字符串
- python随笔2
- java string 字符集编码
- java.util.TreeMap.headMap()方法实例
- Java Process 创建linux用户
- mysql查询错误 FUNCTION nvl does not exist
- Java - 趣味题(3) --- 122345全排序
- C#通用JSON操作类
- 【软考】--软考总结
- caffe灰度图训练
- PowerBuilder Datawindow 滚动条控制
- JDK自带工具一览表