java Comparator为什么没完成排序?

            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());                
            }
白衣染霜花
浏览 617回答 1
1回答

万千封印

... return Long.toString(novel1.getHeat()).compareTo(Long.toString(novel0.getHeat())); String.compareTo(String arg);是按照字典排序的规则,而不是比较值的大小,示例如下:232231223123想要按照Long型值的大小排序: ... return novel0.getHeat().compareTo(novel1.getHeat());
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java