如何对map的value进行升序排序 请高手指点!!! 不是使用sort 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class TestSort { int[] iSort = new int[10]; Map map = new TreeMap(); void setSort(int[] a) { for (int i = 1; i < a.length; i++) { a[i] = (int) (Math.random() * 100); map.put(a[i], i); System.out.println(map.get(a[i]) + " " + a[i]); } } void isSort(Map m) { Set set = m.entrySet(); Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry entry = (Entry) it.next(); System.out.println(entry.getValue() + " " + entry.getKey()); } } public static void main(String[] args) { TestSort ts = new TestSort(); ts.setSort(ts.iSort); System.out.println("==========="); ts.isSort(ts.map); }} 你用Map map = new LinkedHashMap();linkedHashMap是自动排序的Map 自定义hash算法给hashMap即可。 求你们看一眼Java说明文档Java tutorials行不?我前天刚翻译Map,还被推荐了下。今天就有人问这个问题我真崩溃了。 http://java.sun.com/docs/books/tutorial/collections/interfaces/map.html自己去看这个。看不懂就看看词典。哥。 我晕,你不要误导哦LinkedHashMap不是自动排序的TreeMap才是即使TreeMap也不是按照值排序的,是按键排序 迷茫 LinkedHashMap 是记录的 帮忙解决问题 如何把目录下文件名写到一个list中去? 考考你的智商 安装了 JESE 运行时版本,能运行 J2EE程序吗? 我需要在我的程序里建立100多个线程,几百万个对象,不知性能会怎么样? 请帮忙看看这个IO错误,谢谢。 .jar 双击后不能运行也没有任何反应 哪位帮看一下,是啥问题? !!大送分98分! 请教JAVA中读一个文件的时候 我用file.setReadOnly()后怎么解开? 请求各位帮忙,关于绘制图像 无聊,搞个题目玩玩 比对二个Vector找出对方没有的数据
Map map = new TreeMap(); void setSort(int[] a) {
for (int i = 1; i < a.length; i++) {
a[i] = (int) (Math.random() * 100);
map.put(a[i], i);
System.out.println(map.get(a[i]) + " " + a[i]);
}
} void isSort(Map m) { Set set = m.entrySet(); Iterator it = set.iterator(); while (it.hasNext()) {
Map.Entry entry = (Entry) it.next();
System.out.println(entry.getValue() + " " + entry.getKey()); }
} public static void main(String[] args) {
TestSort ts = new TestSort();
ts.setSort(ts.iSort);
System.out.println("===========");
ts.isSort(ts.map); }
}
我晕,你不要误导哦LinkedHashMap不是自动排序的
TreeMap才是即使TreeMap也不是按照值排序的,是按键排序