java对list的常用操作(排序,分组,去重)_开发语言

1.去重

 public static ArrayList<OrganizationInfoBO> removeDuplicteUsers(ArrayList<OrganizationInfoBO> listOrganizationInfoBo) {
Set<OrganizationInfoBO> setBo = new TreeSet<OrganizationInfoBO>(new Comparator<OrganizationInfoBO>() {
@Override
public int compare(OrganizationInfoBO o1, OrganizationInfoBO o2) {
return o1.getId().compareTo(o2.getId());
}
});
setBo.addAll(listOrganizationInfoBo);
return new ArrayList<OrganizationInfoBO>(setBo);
}

2.分组

Map<String, List<AttendRulesInfoBO>> group = resultBo(list对象).
stream().collect(Collectors.groupingBy
(AttendRulesInfoBO(list中VO)::getLateClass(VO中get方法)));

3.排序

            //按照条码类别倒序,条码编码正序排列
Collections.sort(result, new Comparator<BarcodeManageVo>() {
@Override
public int compare(BarcodeManageVo bo1, BarcodeManageVo bo2) {
return bo2.getBatchCode().compareTo(bo1.getBatchCode());
//String的逆序排列
}
});