I have this simple instruction
Stream.concat(manager.getChild().stream(),
manager1.getChild().stream())
.map(dev -> dev.getSalary())
.reduce(0, Integer::max);
that concats two List and return the developer that earning more. This returns the maximum salary of the objects in the stream, but how can I retrieve the object that has the maximum salary?
reducehere?mapandreduceand usemaxinstead with an appropriateComparatorthat compares by salary.Employee rich = Stream.concat(manager.getChild().stream(), manager1.getChild().stream()) .max((dev1, dev2) -> Integer.max(dev1.getSalary(), dev2.getSalary())).get();but not work very well.