Map<String, List<ICBmEvaluationTableDTO>> collect =
tableList.stream().collect(Collectors.groupingBy(ICBmEvaluationTableDTO::getTitleId,
() -> new TreeMap<>(new TitleIdComparator()), Collectors.toList()));
按ICBmEvaluationTableDTO::getTitleId分组,按new TitleIdComparator()工具类定义的方法排序
工具类:返回正数表示o1大于o2,返回负数表示o1小于o2,返回0表示相等
public class TitleIdComparator implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
if (StringUtils.isBlank(o1) || StringUtils.isBlank(o2)){
return StringUtils.isBlank(o1) ? -1 : 1;
}
String[] o1SN = o1.split("\\.");
String[] o2SN = o2.split("\\.");
if (o1SN.length != o2SN.length){
throw new IllegalArgumentException("排序字符串不合法");
}
int compare = 0;
for (int i = 0; i < o1SN.length; i++) {
compare = Integer.parseInt(o1SN[i]) - Integer.parseInt(o2SN[i]);
if (compare != 0){
return compare;
}
}
return compare;
}
}