java list对象按照某个属性去重

/**
* 去重
*
* @param orderList
* @return
* @author jqlin
*/
private static List<ansVo> removeDuplicateOrder(List<ansVo> orderList) {
Set<ansVo> set = new TreeSet<ansVo>(new Comparator<ansVo>() {
@Override
public int compare(ansVo a, ansVo b) {
// 字符串则按照asicc码升序排列
return a.getId().compareTo(b.getId());
}
});

set.addAll(orderList);
return new ArrayList<ansVo>(set);
}

//按照多个字段去重

private static ArrayList<Map> removeDuplicateBussinessname(List<Map> returnAllList) {
Set<Map> set = new TreeSet<Map>(new Comparator<Map>() {
@Override
public int compare(Map o1, Map o2) {
int compareToResult = 1;// ==0表示重复
// 字符串则按照asicc码升序排列
if ((CustomString.GetMapValue(o1, "name").equals(CustomString.GetMapValue(o2, "name")))
&& (CustomString.GetMapValue(o1, "wdata").equals(CustomString.GetMapValue(o2, "wdata")))
&&( CustomString.GetMapValue(o1, "wtime").equals(CustomString.GetMapValue(o2, "wtime")))
&& (CustomString.GetMapValue(o1, "wsec").equals(CustomString.GetMapValue(o2, "wsec"))))
{
compareToResult = 0;
}
return compareToResult;

}
});
set.addAll(returnAllList);
return new ArrayList<Map>(set);
}

posted @ 2019-02-16 14:07  逆水乘舟,不进则退  阅读(2805)  评论(0编辑  收藏  举报