Java对象类型集合,根据对象中的属性进行冒泡排序,并只保留前十条数据

 List<ProjectEntity> list = this.baseMapper.getNotFinished();
 List<ProjectEntity> orderByList;
 //根据总进度从高到低排序
 for (int i = 0; i < list.size() - 1; i++) {
     
     for (int j = 0; j < list.size() - i - 1; j++) {
     
         if (list.get(j).getTotalProgress() < list.get(j + 1).getTotalProgress()) {
     
             ProjectEntity temp = list.get(j);
             list.set(j, list.get(j + 1));
             list.set(j + 1, temp);
         }
     }
 }
  //取排名前10的
 if (list.size() > 10) {
     
     orderByList = list.subList(0, 10);
 } else {
     
     orderByList = list;
 }

你可能感兴趣的:(java问题,java)