Vidyalelo
Computer Science · Q236

Kotlin Programming MCQ for Competitive Exams, Interviews, and Certifications

Engineering and GATE · Computer Science · question 236

Q236

You would like to group a list of students by last name and get the total number of groups. Which line of code accomplishes this, assuming you have a list of the Student data class? Data class Student(val firstName: String, val lastName: String)

A.
Println(students.groupBy{ it.lastName }.count())
Answer
B.
Println(students.groupBy{ it.lastName.first() }.fold().count())
C.
Delegates.rx()
D.
Println(students.groupingBy{ it.lastName.first() }.size())

Answer: Option A

Solution

Answer: Option A
No explanation is given for this question Let's Discuss on Board