int top = Integer.parseInt(map.get("top"));
List<NovelNews> novelNewsList = NovelMongo.GetAllNovel();
Collections.sort(novelNewsList, new Comparator() {
public int compare(Object obj0, Object obj1) {
NovelNews novel0 = (NovelNews) obj0;
NovelNews novel1 = (NovelNews) obj1;
return Long.toString(novel1.getHeat()).compareTo(Long.toString(novel0.getHeat()));
}
});
for(int i = 0; i <= top - 1; i++){
System.out.println(novelNewsList.get(i).getHeat());
}
String.compareTo(String arg); is based on dictionary sorting rules, rather than comparing the size of values. The example is as follows:
23
2231
223
123
Want to sort by the size of Long values: