From the course: Java SE 21 Developer (1Z0-830) Cert Prep

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Question deep dive

Question deep dive

- Exam-style question time again. So there's the basic question, we have a skeleton for a Student class, and a list of students being made that's then gonna go through a collect operation. Might like to pause the video and take a good look at that before we bring in the options, 'cause the screen is about to get kind of cluttered. All right, here come the options. So let's take a look at this. We have our Student with a name and a single favoriteCourse, in this case. We create three of them where Fred likes Programming, Jim has no favorite course, and Sheila likes Tensor Calculus. We draw a stream from them, and we perform a collect operation. So clearly, a large part of this question is gonna be something to do with the collecting. The collect is a Collectors.groupingBy. So we know that the first argument to a groupingBy is the classifier or key extractor. So first, we will find the getFavorite. And that means we…

Contents