I have a POJO class from which I want to collect all the POJO objects that matches the max value of a given POJO variable.
I have the below POJO class
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IPTraceData implements Serializable {
private String factId;
private long startIp;
private long endIp;
private int confidence;
private LocalDate date;
private long ipaddr;
}
I want to get all the POJO object which match with the max value of confidence variable.
I am able to get the results using the below code in Java 8.
int max = allTraces.stream()
.max(Comparator.comparing(IPTraceData::getConfidence))
.get()
.getConfidence();
List<IPTraceData> traceData = allTraces
.stream()
.filter(m -> m.getConfidence() == max)
.collect(Collectors.toList());
However, I am trying to write a code in Java 8 using a single stream statement. How can I achieve the same using the single stream statement?