0
0
Android Kotlinmobile~10 mins

Collections (List, Map, Set) in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a mutable list of strings named fruits.

Android Kotlin
val fruits = mutableListOf[1]
Drag options to blanks, or click blank then click option'
A{"Apple", "Banana"}
B<String>()
C["Apple", "Banana"]
D("Apple", "Banana")
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] which is not valid syntax for list creation in Kotlin.
Using parentheses () without specifying the type.
2fill in blank
medium

Complete the code to add the string "Orange" to the fruits list.

Android Kotlin
fruits.[1]("Orange")
Drag options to blanks, or click blank then click option'
Apush
Binsert
Cappend
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using append() which is not a Kotlin list method.
Using push() which is used in other languages like JavaScript.
3fill in blank
hard

Fix the error in the code to create a map with keys as strings and values as integers.

Android Kotlin
val scores = mapOf<String, Int>[1]("Alice" to 10, "Bob" to 8)
Drag options to blanks, or click blank then click option'
A(
B[
C{
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] which causes syntax errors.
Using curly braces {} which are for lambda expressions.
4fill in blank
hard

Fill both blanks to create a set of integers and add the number 5 to it.

Android Kotlin
val numbers = mutableSetOf[1](1, 2, 3)
numbers.[2](5)
Drag options to blanks, or click blank then click option'
A<Int>
Badd
Cappend
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Using append() which is not a Kotlin method for sets.
Omitting the type specification which can cause type inference issues.
5fill in blank
hard

Fill all three blanks to create a map from strings to integers, add a new pair, and retrieve a value.

Android Kotlin
val ages = mutableMapOf[1]("John" to 25, "Jane" to 30)
ages.[2]("Mike", 20)
val age = ages[[3]]
Drag options to blanks, or click blank then click option'
A<String, Int>
Bput
C"Mike"
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using add() instead of put() to add to a map.
Using a variable instead of the string key when retrieving the value.