项目遇到使用的Set中数据,需要对其有序输出,只能将Set转化为有序的List或者LinkedList,有条件的也可以使用TreeSet。List中排序:
List<ZxFraudCpws> fraudCpwss = new ArrayList<ZxFraudCpws>();
fraudCpwss.addAll(zxFraudBase.getZxFraudCpwsSet()); // zxFraudBase.getZxFraudCpwsSet()为Set型
Collections.sort(fraudCpwss, new Comparator<ZxFraudCpws>() {
public int compare(ZxFraudCpws o1, ZxFraudCpws o2) {
// 按照sortTime进行降序排列
if (Long.parseLong(o1.getSortTime()) > Long.parseLong(o2.getSortTime())) {
return -1;
}
if (o1.getSortTime() == o2.getSortTime()) {
return 0;
}
return 1;
}
});