0
0
Kotlinprogramming~10 mins

Set creation (setOf, mutableSetOf) 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 set with elements 1, 2, and 3.

Kotlin
val numbers = [1](1, 2, 3)
Drag options to blanks, or click blank then click option'
AmutableSetOf
BlistOf
CsetOf
DarrayOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableSetOf creates a mutable set, not immutable.
Using listOf creates a list, not a set.
2fill in blank
medium

Complete the code to create a mutable set with elements "apple" and "banana".

Kotlin
val fruits = [1]("apple", "banana")
Drag options to blanks, or click blank then click option'
AsetOf
BmutableSetOf
CarrayOf
DlistOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using setOf creates an immutable set that cannot be changed.
Using listOf creates a list, not a set.
3fill in blank
hard

Fix the error in the code to create an immutable set of integers.

Kotlin
val nums = setOf[1]1, 2, 3)
Drag options to blanks, or click blank then click option'
A(
B[
C{
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Missing the opening parenthesis.
4fill in blank
hard

Fill both blanks to create a mutable set and add an element "orange".

Kotlin
val fruits = [1]("apple", "banana")
fruits.[2]("orange")
Drag options to blanks, or click blank then click option'
AmutableSetOf
BsetOf
Cadd
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using setOf creates an immutable set that cannot add elements.
Using remove instead of add to insert elements.
5fill in blank
hard

Fill all three blanks to create an immutable set of numbers, check if it contains 5, and print the result.

Kotlin
val numbers = [1](1, 2, 3, 4, 5)
val hasFive = numbers.[2](5)
println([3])
Drag options to blanks, or click blank then click option'
AsetOf
Bcontains
ChasFive
DmutableSetOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutableSetOf instead of setOf for immutable set.
Printing the function call instead of the variable.
Using wrong method to check membership.