我有一个自定义类,只有4个项目属于Date类型。该类称为最新
type1将日期时间称为日期格式。我将字符串类型转换为日期格式。
我尝试仅在2018-09-30 18:57之后获得这些条目,然后尝试打印它们。课堂上有4个项目,理想情况下,我想打印出构成课程中每个项目的所有4个项目。有人可以协助吗?
final String type1 = "2018-09-30 18:57";
SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date date = dt.parse(type1);
Stream<List<Date>> workRequestFileTransAuditListforSubmission = attributes.stream()
.filter(file -> file.getAcceptanceTime() > date)
.map(Latest::getAcceptanceTime)
.collect(Collectors.toList());
workRequestFileTransAuditListforSubmission.forEach(System.out::println);`
答案 0 :(得分:1)
使用after()
或before()
方法比较两个日期。而且您不需要在map
个日期中使用collect
和print
。
attributes.stream()
.filter(file -> file.getAcceptanceTime().after(date))
.forEachOrdered(file -> System.out.println(file.getAcceptanceTime()));