主要是通过TreeMap来排序。
import java.util.Iterator;
import java.util.Set;
import java.util.TreeMap;
public class MapTest
{
public static void main(String args[])
{
TreeMap<Integer, String> maps = new TreeMap<Integer, String>();
maps.put(2, "Test2");
maps.put(1, "Test1");
maps.put(4, "Test4");
maps.put(3, "Test3");
Set set = maps.keySet();
Iterator iter = set.iterator();
while (iter.hasNext())
{
Object key = iter.next();
System.out.println(key + " " + maps.get(key));
}
}
}
posted on 2011-08-02 10:09
Jarry 阅读(203)
评论(0) 编辑 收藏 所属分类:
Java