rendered paste bodypackage sonstiges;import java.util.Comparator;import java.util.HashMap;import java.util.Map;import java.util.TreeMap;import java.util.TreeSet;public class HashMapTest { private static class ValueComparator implements Comparator { public int compare(Object o1, Object o2) { Map.Entry e1 = (Map.Entry) o1; Map.Entry e2 = (Map.Entry) o2; int e1count = 0; int e2count = 0; try { e1count = Integer.parseInt(((String)e1.getValue()).split("|")[1]); e2count = Integer.parseInt(((String)e2.getValue()).split("|")[1]); } catch (Exception e) { e.printStackTrace(); } if (e1count == e2count) { return 0; } else if (e1count > e2count) { return -1; } else { return 1; } } } @SuppressWarnings("unchecked") public static void main(String[] args) { HashMap map = new HashMap(); map.put("1", "300|5"); map.put("2", "300|10"); map.put("3", "300|3"); map.put("4", "300|8"); System.out.println(map); TreeSet set = new TreeSet(new ValueComparator()); set.addAll(map.entrySet()); System.out.println(set); }}