代号一:通过整数/整数方法编写排序比较



代号 One 不接受基元类型 (int(,所以我尝试使用 Integer 编写以下比较器:

private static class CelebrityPopularityComparator implements Comparator<Celebrity> {
    @Override
    public int compare(Celebrity celebrity1, Celebrity celebrity2) {
        Integer celebrity1PopularitySum = celebrity1.getCelebrityPopularitySum();
        Integer celebrity2PopularitySum = celebrity2.getCelebrityPopularitySum();
        Integer comparisonResult = Integer.valueOf(celebrity1PopularitySum.compareTo(celebrity2PopularitySum));
        return comparisonResult;
    }
}

我尝试了很多方法,但它不起作用。它不会将生成发送到服务器。我能做些什么来修复它?谢谢!

试试这个:

        Integer celebrity1PopularitySum = celebrity1.getCelebrityPopularitySum();
        Integer celebrity2PopularitySum = celebrity2.getCelebrityPopularitySum();
        if(celebrity1PopularitySum.equals(celebrity2PopularitySum)){
            return 0;
        }else if(celebrity1PopularitySum.intValue() < celebrity2PopularitySum.intValue()){
            return -1;
        }else{
            return 1;
        }

相关内容

  • 没有找到相关文章

最新更新