import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@Composable
fun CollectionsDemo() {
val fruits: List<String> = listOf("Apple", "Banana", "Cherry")
val numbers: Map<Int, String> = mapOf(1 to "One", 2 to "Two")
val colors: Set<String> = setOf("Red", "Green", "Blue")
Column {
Text(text = "List:")
for (fruit in fruits) {
Text(text = "- $fruit")
}
Text(text = "")
Text(text = "Map:")
for ((key, value) in numbers) {
Text(text = "Key: $key, Value: $value")
}
Text(text = "")
Text(text = "Set:")
for (color in colors) {
Text(text = "- $color")
}
}
}This solution defines three Kotlin collections: a List of fruits, a Map of numbers, and a Set of colors.
It uses a Column composable to arrange the text vertically.
Each collection is displayed with a header and then its items are shown using Text composables in a simple loop.
This shows how to use Kotlin collections and display their contents in a Compose UI.