Map中有序存储

来源:互联网 发布:在线网络投资靠谱吗 编辑:程序博客网 时间:2024/06/04 18:35

我们都知道,Map中是以key-value形式存储的,通常java.util.Map是无序的,例如:

 

Map map=new HashMap();

 

map.put("yi","壹");

map.put("er","贰");

map.put("san","叁");

map.put("si","肆");

 

这样存储的值,不一定是按顺序的,如果我们要想让它像List那样是不可能的。

 

这里看看http://commons.apache.org/collections/apidocs/index.html这个API就有办法了。

 

 

org.apache.commons.collections.map 
Class ListOrderedMap

java.lang.Object  extended by org.apache.commons.collections.map.AbstractMapDecorator      extended by org.apache.commons.collections.map.ListOrderedMap
All Implemented Interfaces:
java.io.Serializable, java.util.Map, IterableMap, OrderedMap

就这个类可以让我们的Map也能像List一样有序了。



转载自:http://blog.csdn.net/guoyankun/article/details/11217221

0 0
原创粉丝点击