Kotlin Program - Study Mode

[#71] Your code need to try casting an object. If the cast is not possible, you do not want an exception generated, instead you want null to be assigned. Which operator can safely cast a value?
Correct Answer

(A) as?

[#72] Which is the correct declaration of an integer array with a size of 5?
Correct Answer

(B) val arrs = IntArray(5)

[#73] Which command will return the length of a String in Kotlin?
Correct Answer

(A) str.length

[#74] Which view attribute do you use to set the width of a View so that it adjusts to fit the content?
Correct Answer

(B) android:layout_width="wrap_content"

[#75] 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)
Correct Answer

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