如何根据对象的两个属性对名为“serviceNeedingTasks”的arraylist进行排序

时间:2018-05-01 19:06:55

标签: java sorting arraylist collections

有谁知道如何根据“任务”的两个属性“p_t”和“weight”的乘法对“serviceNeedingTasks”进行排序?它似乎不正确,因为它只是基于“p_t”排序。

Collections.sort(serviceNeedingTasks, new Comparator<Tasks>() {
          public int compare(Tasks c1, Tasks c2) {
            if (c1.p_t)*(c1.weight) > (c2.p_t)*(c1.weight) return -1;
            if (c1.p_t)*(c1.weight) < (c2.p_t)*(c1.weight) return 1;
            return 0;
          }});

0 个答案:

没有答案