一切都很好,但我希望locationName按排序顺序,locationMasterList有Integer,String和Double Objects .. 以下是我的代码......
List<LocationMaster> locationMasterList = locationMasterService.findByProperty("locationId", locationId);
for (int n = 0; n < locationMasterList.size(); n++) {
YearwiseBudget yearwiseBudget1 = new YearwiseBudget();
String locationName = locationMasterList.get(n).getLocationNameE();
Integer distId = locationMasterList.get(n).getLocationId();
yearwiseBudget1.setRecordId(recordId.longValue());
yearwiseBudget1.setAllocation(allocation);
yearwiseBudget1.setExpenditure(expenditure);
yearwiseBudget1.setLocationName(locationName);
yearwiseBudget1.setAllocGen(allocGen);
yearwiseBudget1.setAllocSC(allocSC);
yearwiseBudget1.setAllocST(allocST);
yearwiseBudget1.setExpGen(expGen);
yearwiseBudget1.setExpSC(expSC);
yearwiseBudget1.setExpST(expST);
yearwiseBudget1.setDistrictId(distId);
YearwiseBudgetList2.add(yearwiseBudget1);
}
答案 0 :(得分:0)
让YearlyBudget
实施Comparable
并在locationName
成员上进行比较。
public class YearwiseBudget implements Comparable<YearwiseBudget> {
private String locationName;
.
.
.
@Override
public int compareTo(YearwiseBudget other) {
return other.locationName.compareTo(locationName);
}
}
然后在列表中使用Collections.sort(List<T> list)
。