总结:Collections可以对List进行排序;如果想对Map进行排序,可以将Map转化成List,进行排序;
public static void hashMapSortTest()
Map<String, new HashMap<String,
maps.put( "boy" , 8 );
maps.put( "cat" , 7 );
maps.put( "dog" , 1 );
maps.put( "apple" , 5 );
Iterator
while (i.hasNext())
Map.Entry<String,
}
List<Map.Entry<String, new ArrayList<Map.Entry<String,
Collections.sort(info, new Comparator<Map.Entry<String,
public int compare(Map.Entry<String,
return obj1.getValue().compareTo(obj2.getValue());
}
});
}
|