我正在尝试在功能界面中格式化日期,但我不知道是否可能
SimpleDateFormat dt1 = new SimpleDateFormat("ddmmyyyyy");
List<MenuPrice> menuPrices = findAll(restaurant);
menuPrices.parallelStream()
.collect(Collectors.groupingBy(dt1.format(MenuPrice::getUpdateDate)));
答案 0 :(得分:7)
有可能,但没有方法参考:
Map<String,List<MenuPrice>>
menuPrices.parallelStream()
.collect(Collectors.groupingBy(m -> dt1.format(m.getUpdateDate())));
答案 1 :(得分:4)
您可以为该顺便说一句创建方法,以使内容更易读:
private static String formatUpdatedDate(MenuPrice menu){
return dt1.format(menu.getUpdatedDate());
}
并使用它:
.collect(Collectors.groupingBy(YourClass::formatUpdatedDate)