排序?
不是吧这是遍历
map.keySet().iterator();
不是吧这是遍历
map.keySet().iterator();
解决方案 »
- javaSE学习笔记
- 戏说深度优先算法(代码)
- 一个找工作的问题,虽然根栏目要求不一样,但是想听听大家的意见
- Timer中得任务出了异常怎么捕获?
- 问个菜鸟问题
- 为什么我直用JDBC连sql server2000 取数据时要用选后顺序呢?怎么解决呢?
- frame为什么声明为 static 的?
- 一个小问题!(100不够再加)
- 线程的wait ,notify,synchronized问题,请帮忙分析一小段程序,小弟不胜感激(特别是ajiao)
- 初学告急,各位大虾帮忙进来看看!!!
- java的throw Eeception和throws Eeception有什么区别
- 用java编写一个完整的关于2D移动,旋转,错切,缩放等的程序,正确给200分
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);
}
}}
随便写了写
自己看看吧
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])) ;
}}
至于内部实现逻辑,对外界使用一点影响也没有。BTW:是二插树排序。