import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class MapSort {
\x09public static void main(String[] args) {
\x09\x09String str = "adf adf ad adf adf ad ad f ad ad";
\x09\x09String[] items = str.split(" ");
\x09\x09Map map = new HashMap();
\x09\x09for (String s : items) {
\x09\x09\x09if (map.containsKey(s))
\x09\x09\x09\x09map.put(s, map.get(s) + 1);
\x09\x09\x09else {
\x09\x09\x09\x09map.put(s, 1);
\x09\x09\x09}
\x09\x09}
\x09\x09List list = new ArrayList();
\x09\x09for (Entry entry : map.entrySet()) {
\x09\x09\x09list.add(entry);
\x09\x09}
\x09\x09Collections.sort(list, new EntryComparator());
\x09\x09for (Entry obj : list) {
\x09\x09\x09System.out.println(obj.getKey() + "\t" + obj.getValue());
\x09\x09}
\x09}
}
class EntryComparator implements Comparator {
\x09public int compare(Entry o1, Entry o2) {
\x09\x09return o1.getValue() > o2.getValue() ? 0 : 1;
\x09}
}
参数你可以自己修改!