- Commons Collections 教程
- Commons Collections - 主页
- Commons Collections - 概述
- Commons Collections - 环境设置
- Commons Collections - 包接口
- Commons Collections - BidiMap 接口
- Commons Collections - MapIterator 接口
- Commons Collections - 有序映射接口
- Commons Collections - 忽略 Null
- Commons Collections - 合并 & 排序
- Commons Collections - 转换对象
- Commons Collections - 过滤对象
- Commons Collections - 安全空检查
- Commons Collections - 包含
- Commons Collections - 相交
- Commons Collections - 差集
- Commons Collections - 并集
- Commons Collections 资源
- Commons Collections - 快速指南
- Commons Collections - 有用资源
- Commons Collections - 讨论
Commons Collections - 有序映射接口
OrderedMap 是一种新的映射接口,用于保留元素添加的顺序。LinkedMap 和 ListOrderedMap 是两种可用的实现。此接口支持 Map 的迭代器,并允许在 Map 中双向迭代,向前或向后。以下示例对此进行了说明。
MapIterator 接口示例
OrderedMapTester.java 的一个示例如下 −
import org.apache.commons.collections4.OrderedMap;
import org.apache.commons.collections4.map.LinkedMap;
public class OrderedMapTester {
public static void main(String[] args) {
OrderedMap<String, String> map = new LinkedMap<String, String>();
map.put("One", "1");
map.put("Two", "2");
map.put("Three", "3");
System.out.println(map.firstKey());
System.out.println(map.nextKey("One"));
System.out.println(map.nextKey("Two"));
}
}
输出
结果如下 −
One Two Three
广告