How to use Comparator in Java to sort

后端 未结 14 1982
时光取名叫无心
时光取名叫无心 2020-11-22 02:19

I learned how to use the comparable but I\'m having difficulty with the Comparator. I am having a error in my code:

Exception in thread \"main\" java.lang.C         


        
14条回答
  •  余生分开走
    2020-11-22 02:59

    public static Comparator JobEndTimeComparator = new Comparator() {
                public int compare(JobSet j1, JobSet j2) {
                    int cost1 = j1.cost;
                    int cost2 = j2.cost;
                    return cost1-cost2;
                }
            };
    

提交回复
热议问题