排序?
不是吧这是遍历
map.keySet().iterator();

解决方案 »

  1.   

    用TreeMap,在你put的时候,TreeMap自动进行排序。
      

  2.   

    就是要排序,不是遍历TreeMap能按升或降序排序吗?TreeMap是不是二叉树堆排序
      

  3.   

    把它换成array 然后 转换成list 可排序。
      

  4.   

    import java.util.*;class Test implements Comparator {
      public int compare(Object o1,Object o2) {
        int i1 = new Integer((String) o1).intValue();
        int i2 = new Integer((String) o2).intValue();    if (i1 > i2) {
          return 1;
        } else {
          return -1;
        }
      }
    }public class Untitled3 {
      public Untitled3() {
      }
      public static void main(String[] args) {
        Untitled3 untitled31 = new Untitled3();
        java.util.TreeMap map = new TreeMap(new Test());
        map.put("2", "asd");
        map.put("1", "dsa");
        Iterator iterator = map.keySet().iterator();
        while(iterator.hasNext()) {
          String str = (String) iterator.next();
          System.out.println(str);
        }
      }}
    随便写了写
    自己看看吧
      

  5.   

    import java.util.*;
    public class hmap { public static void main(String args[]){
      HashMap hm = new HashMap();
    hm.put("b","bbbb") ;
    hm.put("a","aaaa") ;
    hm.put("d","dddd") ;
    hm.put("c","ccccc") ; Set set = hm.keySet() ;
    Iterator it = set.iterator() ;
                      Object obj[] = new Object[set.size()]; int i=0;
    while (it.hasNext() ){
     obj[i] = it.next() ;
     i++;
    }
    Arrays.sort(obj) ;
    for(int j=0;j<obj.length ;j++)
      System.out.println(hm.get(obj[j])) ;
    }}
      

  6.   

    TreeMap按升序排。
    至于内部实现逻辑,对外界使用一点影响也没有。BTW:是二插树排序。