java 数组list 找出最早最晚
// 找到最早的小时和最晚的小时,并具体到分钟 Optional<LocalTime> earliestTime = adminEventInfoDTOList.stream() .map(dto -> dto.getCreateTime().toLocalTime()) .min(LocalTime::compareTo); Optional<LocalTime> latestTime = adminEventInfoDTOList.stream() .map(dto -> dto.getCreateTime().toLocalTime()) .max(LocalTime::compareTo); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); earliestTime.ifPresent(dto -> { adminPatrolEventStatisticsDTO.setEarliestTime("最早:" + dto.format(formatter)); }); latestTime.ifPresent(dto -> { adminPatrolEventStatisticsDTO.setLatestTime("最晚:" + dto.format(formatter)); });