Comparator.comparing(ResLink::getGmtModified).reversed() 与 sorted((str1, str2) -> str1.compareTo(str2))均可以做比较
HashSet<String> hashSet = sysHospitalizationList.stream()
.map(sysHospitalization -> sysHospitalization.gethBed())
.filter(str -> !str.equals("") && !str.equals(" "))
.collect(Collectors.toCollection(HashSet::new));
List<String> bedList = hashSet.stream()
.sorted((str1, str2) -> str1.compareTo(str2))
.collect(Collectors.toList());
return bedList;
List<AdminUserDTO> resultList = sysUserDao.selectAll();
resultList .sort(Comparator.comparing(AdminUserDTO::getpName).reversed());
本文介绍如何使用 Java 的 Stream API 对集合进行排序,包括创建 HashSet 并转换为有序 List 的过程,同时展示了两种排序方法:Comparator.comparing 和 sorted 方法。
976

被折叠的 条评论
为什么被折叠?



