setOf() do in Kotlin?setOf() creates an immutable set, which means you cannot add or remove elements after creation.
mutableSetOf() different from setOf()?mutableSetOf() creates a mutable set, allowing you to add or remove elements after the set is created.
setOf()?You will get a compilation error because the set is immutable and does not support modification.
val fruits = mutableSetOf("apple", "banana", "cherry")Because sets automatically prevent duplicate elements and provide faster checks for whether an element exists.
setOf() creates an immutable set, while mutableSetOf() creates a mutable set.
add() on a set created with setOf()?Since setOf() returns an immutable set, calling add() is not allowed and causes a compilation error.
mutableSetOf creates an empty mutable set of integers.
Sets do not allow duplicate elements. They may or may not maintain order depending on implementation.
val s = setOf(1, 2, 3)?setOf() returns an immutable Set of the given type.