1.日期倒序(最新日期在集合最前面)
list.sort((m1, m2) -> m2.getReplydate().compareTo(m1.getReplydate()));
1.1 降序排列日期数据,处理空日期的问题(将空的日期数据放最后)
Comparator<ZclInfoDto> comparator3 = Comparator.comparing(ZclInfoDto::getDtCreateDate, Comparator.nullsFirst(naturalOrder()) ); List<ZclInfoDto> orderList3 = zclInfoDtoList.stream().sorted(comparator3.reversed()).collect(Collectors.toList());
2.//使用@Builder注解后,可以直接通过Builder设置字段参数
@Data @Builder @NoArgsConstructor @AllArgsConstructor
test1 t1=new test1.test1Builder() .name("wang") .age("12") .sex("man") .build();
3.java8对list对象多属性去重
ArrayList<XckyxxVo> xckyxxVoList1 = xckyxxVoListnew.stream().collect( Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<> (Comparator.comparing(XckyxxVo::getSaapp) .thenComparing(XckyxxVo::getKyh) .thenComparing(XckyxxVo::getSha1))), ArrayList::new));
4.集合分页
List<XckyxxVo> pagenewViewList = newViewList.stream().skip((pageDomain.getPageNum()-1)*pageDomain.getPageSize()).limit(pageDomain.getPageSize()). collect(Collectors.toList());
4.1删除list集合中的对象
boolean remove = zjlList.remove(sanLiuVo1);
5.日期比较
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = sdf.parse("2009-12-31");
Date date2 = sdf.parse("2019-01-31");
System.out.println("date1 : " + sdf.format(date1));
System.out.println("date2 : " + sdf.format(date2));
if (date1.compareTo(date2) > 0) {
System.out.println("Date1 时间在 Date2 之后");
} else if (date1.compareTo(date2) < 0) {
System.out.println("Date1 时间在 Date2 之前");
} else if (date1.compareTo(date2) == 0) {
System.out.println("Date1 时间与 Date2 相等");
6.给前端返回隐藏字段
@JsonIgnore
不处理前:
处理后:
7.list数组对象中的某一个值转String
String joinName = list.stream().map(Student::getName).collect(Collectors.joining(",", "(", ")")); // (aa,bb,cc)