exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 24 discussion

Actual exam question from Oracle's 1z0-809
Question #: 24
Topic #: 1
[All 1z0-809 Questions]

Given:
class Student {
String course, name, city;
public Student (String name, String course, String city) {
this.course = course; this.name = name; this.city = city;
}
public String toString() {
return course + ":" + name + ":" + city;
}
and the code fragment:
List<Student> stds = Arrays.asList(
new Student ("Jessy", "Java ME", "Chicago"),
new Student ("Helen", "Java EE", "Houston"),
new Student ("Mark", "Java ME", "Chicago"));
stds.stream()
.collect(Collectors.groupingBy(Student::getCourse))
.forEach(src, res) -> System.out.println(scr));
What is the result?

  • A. [Java EE: Helen:Houston] [Java ME: Jessy:Chicago, Java ME: Mark:Chicago]
  • B. Java EE Java ME
  • C. [Java ME: Jessy:Chicago, Java ME: Mark:Chicago] [Java EE: Helen:Houston]
  • D. A compilation error occurs.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Innovation
Highly Voted 4 years, 6 months ago
a compile error occurs because the getCourse method is not defined if it was, the output would be Java EE Java ME
upvoted 10 times
Ohayou
2 years, 4 months ago
getCourse is added implicit by the compiler because variable course is not private. Correct Answer is B
upvoted 1 times
shivkumarx
4 months ago
incorrect, Java compiler does not do this
upvoted 1 times
...
...
...
Choucou
Highly Voted 4 years, 10 months ago
Correct answer is D
upvoted 9 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 2 weeks ago
Currently compilation error. stds.stream() .collect(Collectors.groupingBy(Student::getCourse)) .forEach(src, res) -> System.out.println(scr)); if code will be like above then B
upvoted 1 times
...
steefaand
5 months, 2 weeks ago
Selected Answer: D
Compile fails since getCourse method is not defined.
upvoted 1 times
...
r1muka5
1 year, 4 months ago
Correct answer is D. Multiple compilation errors.
upvoted 1 times
...
MahdiHamdii
1 year, 7 months ago
Selected Answer: D
D there are too many errors I can count 3 1-missing parentheses near foreach 2- wrong variable in the sout 3- method getCourse isn't defined answer Would be D
upvoted 1 times
...
Ohayou
2 years, 4 months ago
if we correct variable scr to src in line : forEach(src, res) -> System.out.println(scr)); Correct Answer is B else Correct Answer is D
upvoted 2 times
lnrdgst
2 years, 1 month ago
I agree. Also at ".forEach(src, res) -> System.out.println(scr));" it should be ".forEach((src, res) -> System.out.println(src));" Another however is that in the Student class there are no get methods. So answer is D
upvoted 1 times
...
...
WilsonKKerll
2 years, 4 months ago
Answer is B...........
upvoted 1 times
...
chichikim
2 years, 7 months ago
.forEach(src, res) -> System.out.println(scr)); ===> .forEach((src, res) -> System.out.println(src)); Correct Answer is B
upvoted 1 times
...
Samps
3 years, 11 months ago
Correct Answer should be D Lambda is been (forEach Method) and the parameter is more than one and the Type wasn't specified
upvoted 2 times
Ohayou
2 years, 4 months ago
Collectors.groupingBy return Map<String, List<Student>> so we need forEach (BiConsumer) Method Correct Answer is B
upvoted 1 times
...
...
rameasy
3 years, 11 months ago
if It is students.stream().collect(Collectors.groupingBy(Studentee::getCourse)).forEach((src, res) -> System.out.println(src)); then the result is B. Java EE Java ME if It is students.stream().collect(Collectors.groupingBy(Studentee::getCourse)).forEach((src, res) -> System.out.println(res)); then the result is A. [Java EE: Helen:Houston] [Java ME: Jessy:Chicago, Java ME: Mark:Chicago]
upvoted 5 times
...
johnchen88
4 years, 5 months ago
The Correct Answer should be A
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago