0
0
Kotlinprogramming~15 mins

Set creation (setOf, mutableSetOf) in Kotlin - Mini Project: Build & Apply

Choose your learning style9 modes available
Set creation (setOf, mutableSetOf)
📖 Scenario: You are organizing a small party and want to keep track of unique guests who have confirmed their attendance.
🎯 Goal: Build a Kotlin program that creates a set of guest names using setOf and a mutable set using mutableSetOf.
📋 What You'll Learn
Create an immutable set of guest names using setOf
Create a mutable set of guest names using mutableSetOf
Add a new guest to the mutable set
Print both sets to see the guests
💡 Why This Matters
🌍 Real World
Sets are useful to keep track of unique items like guest lists, product IDs, or tags without duplicates.
💼 Career
Understanding sets helps in data processing, filtering duplicates, and managing collections efficiently in software development.
Progress0 / 4 steps
1
Create an immutable set of guests
Create an immutable set called guests using setOf with these exact names: "Alice", "Bob", "Charlie".
Kotlin
Need a hint?

Use val guests = setOf("Alice", "Bob", "Charlie") to create the set.

2
Create a mutable set of guests
Create a mutable set called mutableGuests using mutableSetOf with these exact names: "Alice", "Bob", "Charlie".
Kotlin
Need a hint?

Use val mutableGuests = mutableSetOf("Alice", "Bob", "Charlie") to create the mutable set.

3
Add a new guest to the mutable set
Add the guest "Diana" to the mutable set mutableGuests using the add method.
Kotlin
Need a hint?

Use mutableGuests.add("Diana") to add the new guest.

4
Print both sets
Print the immutable set guests and the mutable set mutableGuests using two separate println statements.
Kotlin
Need a hint?

Use println(guests) and println(mutableGuests) to display the sets.