Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 193

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;

}

public String getCourse() {return course;}

public String getName() {return name;}

public String getCity() {return city;}

and the code fragment:

List 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(res));

What is the result?

    Correct Answer: A

    The code contains a syntax error in the forEach statement. The lambda expression should have parentheses around the parameters 'src' and 'res'. It should be written as .forEach((src, res) -> System.out.println(res));. Due to this syntax error, the code will not compile, resulting in a compilation error.

Discussion
fffffOption: C

C: [Java EE:Helen:Houston][Java ME:Jessy:Chicago, Java ME:Mark:Chicago] tested

jduarteOption: A

Answer A. incompile forEach(src, res) -> System.out.println(res));

jduarte

but answer is C if correct.

steefaandOption: C

C is correct assuming typos.

iSnoverOption: C

The answer is C, this time it has all the methods correctly.