0
0
Kotlinprogramming~10 mins

List creation (listOf, mutableListOf) in 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 an immutable list of integers.

Kotlin
val numbers = [1](1, 2, 3, 4, 5)
Drag options to blanks, or click blank then click option'
AlistOf
BmutableListOf
CarrayListOf
DsetOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableListOf instead of listOf creates a mutable list.
Using setOf creates a set, not a list.
2fill in blank
medium

Complete the code to create a mutable list of strings.

Kotlin
val fruits = [1]("apple", "banana", "cherry")
Drag options to blanks, or click blank then click option'
AlistOf
BsetOf
CmutableListOf
DarrayOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using listOf creates an immutable list that cannot be changed.
Using arrayOf creates an array, not a list.
3fill in blank
hard

Fix the error in the code to create a mutable list of doubles.

Kotlin
val prices = [1](10.5, 20.0, 30.75)
Drag options to blanks, or click blank then click option'
AsetOf
BarrayListOf
ClistOf
DmutableListOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using listOf creates an immutable list that cannot be changed.
Using setOf creates a set, not a list.
4fill in blank
hard

Fill both blanks to create an immutable list and get its size.

Kotlin
val colors = [1]("red", "green", "blue")
val size = colors.[2]
Drag options to blanks, or click blank then click option'
AlistOf
BmutableListOf
Csize
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableListOf instead of listOf for an immutable list.
Using count() instead of size property.
5fill in blank
hard

Fill all three blanks to create a mutable list, add an item, and get the last element.

Kotlin
val animals = [1]("cat", "dog")
animals.[2]("rabbit")
val last = animals.[3]()
Drag options to blanks, or click blank then click option'
AmutableListOf
Badd
Clast
DlistOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using listOf instead of mutableListOf for a mutable list.
Using size instead of last() to get the last element.