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?
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?
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.
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();
B IS CORRECT
C is correct if the las operation has stream(), because when get(true) is executed , List is returned so list no containt count() method
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
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()
get(true) returns a list i mean.