public static void main(String[] args) {
i int[] array = {6,6.5,5.1,1,2,2,3,4,4,4};
Arrays.sort(array);// 给数组排序
int count=0;
int tmp=array[0];
Map map=new HashMap();
for(int i=0; i < array.length; i++) {
if(tmp != array[i]) {
tmp=array[i];
count=1;
} else {
count++;
}
map.put(array[i], count);
}
map=sortByValue(map);
Set<Integer> key = map.keySet();
for (Iterator it = key.iterator(); it.hasNext();) {
Integer s = (Integer) it.next();
System.out.println(s+"出现了"+map.get(s));
}
}
public static Map sortByValue(Map map) {
List list=new LinkedList(map.entrySet());
Collections.sort(list, new Comparator() {
// 将链表按照值得从小到大进行排序
public int compare(Object o1, Object o2) {
return ((Comparable)((Map.Entry)(o2)).getValue