我有一個簡單的類,填寫一個簡單的散列表我想通過hashcode命令值如何做到這一點?如何通過散列碼中的散列碼來排序隨機值
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class Ch11Ex18 {
public static void main(String[] args) {
Random rand = new Random(47);
Map<Integer,Integer> m = new HashMap<Integer,Integer>();
for(int i = 0; i < 10000; i++) {
// Produce a number between 0 and 20:
int r = rand.nextInt(20);
Integer freq = m.get(r);
m.put(r, freq == null ? 1 : freq + 1);
}
System.out.println(m);
}
}
訂購價值在哪裏?只是打印它們?獲取鍵,對它們進行排序,遍歷它們並轉儲值。 – 2012-01-27 18:00:16
proly導出到列表並使用hashCode比較器() – Adrian 2012-01-27 18:00:51