- 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
廣告