I have data:
id|date 1 |12-12-2021 2 |12-12-2021 3 |13-12-2021
Want to get a list of dates: [“12-12-2021”, “13-12-2021”]
Using stream, I can get a map:
txs.stream().collect(Collectors.groupingBy(g -> g.getDate()));
I would like to convert to list in from the stream above.
Advertisement
Answer
groupingBy is not the best choice in your case. Use distinct instead. It will automatically filter out all duplicates.
txs.stream().map(g -> g.getDate()).distinct().collect(Collectors.toList());