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)

Question: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)

1.Println(students.groupBy{ it.lastName }.count())

2.Println(students.groupBy{ it.lastName.first() }.fold().count())

3.Println(students.groupingBy{ it.lastName.first() }.count())

4.Println(students.groupingBy{ it.lastName.first() }.size())


Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!