-2

This is the code that returns the object that has the maximum date starting from a stream, I would like to return a list to me, assuming that there are more records.

How should it be changed?

Comparator<DatoStoricoNominativo> comparator = 
                   Comparator.comparing( DatoStoricoNominativo::getDataFine );
DatoStoricoNominativo dsna = dsn.stream().max(comparator).get();
ernest_k
  • 44,416
  • 5
  • 53
  • 99

1 Answers1

0

You can do another iteration to find out the elements that have same date as dsna, e.g.:

List< DatoStoricoNominativo> elements = dsn.stream()
              .filter(e -> dsna.getDataFine().equals(e.getDataFine())
              .collect(Collectors.toList());
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102