D
D
Dmitry Frolov2020-07-15 15:53:50
Java
Dmitry Frolov, 2020-07-15 15:53:50

In a task using the Stream API, you need to find the employee with the highest salary among those who came in 2017?

Good afternoon!
The task contains a text (txt) list of employees, in the format (Last Name, First Name, salary in numbers (78000) and the date this employee started work in the format (11/11/2018)).
There is a class employees "Employee" in this class the lines are written:
private String name;//name
private Integer salary;//salary
private Date workStart;//start work
as well as getters and setters for these parameters.
The list of employees is entered into an ArrayList:
ArrayList staff = loadStaffFromFile();
From this list, you need to find the employee with the highest salary among those who came in 2017? Using the Stream API in one line. I don't know how to filter employees by 2017? Tell me please.
Here is the beginning of my Stream:

staff.stream().sorted(Comparator.comparing(Employee::getWorkStart)).filter(Вот тут должен быть фильтр поиска по 2017 году. Как это реализовать?).forEach(System.out::println);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
5
5am, 2020-07-15
@FDmitriyA

.filter by workStart ( https://vertex-academy.com/tutorials/en/java-8-str... )
.max by salary ( https://www.geeksforgeeks.org/stream-max-method-ja ... )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question