java Comparator为什么没完成排序?
高洛峰
高洛峰 2017-04-18 10:24:13
0
1
338
            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());                
            }
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
阿神
...
return Long.toString(novel1.getHeat()).compareTo(Long.toString(novel0.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:

...
return novel0.getHeat().compareTo(novel1.getHeat());
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!