1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 129


Given:

and

Which code fragment, when inserted on line 1, gives the number of employees who were born after January 1, 1989 and have a salary greater than 25?

Show Answer
Correct Answer: BD

Given the code, we need to filter the list of employees based on two criteria: the salary being greater than 25 and the birthday being after January 1, 1989. The correct approach is to apply two separate filters to the stream before invoking the count method. The first filter checks the salary condition, and the second filter checks the birthday condition. This can be done using the filter method twice in sequence, followed by count to get the number of such employees. This is effectively achieved with option B, which ensures all employees are filtered correctly based on the given criteria before counting them.

Discussion

4 comments
Sign in to comment
dillemanOption: B
Sep 29, 2023

B is correct. Incorrect -> A: e is not defined. Incorrect -> C and D. get(true) returns a stream so it would work if you add .get(true).stream().count()

dilleman
Sep 29, 2023

get(true) returns a list i mean.

d7bb0b2Option: B
Dec 11, 2023

B is correct, Stream has count method d Collectors.partitioningBy(predicated) generate a map with two keys true, and false, and values has the list of the predicated definied. but List hasn't count method, if used a size this is true

d7bb0b2Option: B
Jan 8, 2024

B IS CORRECT

d7bb0b2
Jan 8, 2024

C is correct if the las operation has stream(), because when get(true) is executed , List is returned so list no containt count() method

ASPushkinOption: B
Apr 30, 2024

answer : B CD will work as well if stream() is inserted in like: .get(true) .stream() .count(); --------------- Predicate < Employee > p = e -> e.getSalary() > 25; LocalDate d = IsoChronology.INSTANCE.date(1989, 1, 1); Predicate < Employee > p1 = e -> e.getBirthday().isAfter(d); Stream < Employee > s = roster.stream(); Map < Boolean, List < Employee >> youngerThan = s.filter(p).collect(Collectors.partitioningBy(e -> e.getBirthday().isAfter(d))); long youngAndRich = youngerThan.get(true).stream().count();